so I have a dataframe that includes strings, ints and floats. To sum up, it looks something like this:
| Date | Col 1 | Col 2 | Col 3 | Col 3 | Col 4 | Col 5 | Col 6 |
|---|---|---|---|---|---|---|---|
| 09/2023 | 181.70 | 17.70 / 22.22 | 14.40 | 109.00 | NaN | 6 | 0 / NTD |
| 06/2023 | 143.60 | 17.00 | 15.30 | 190.05 | NaN | 6 / 11.41 | 1 |
| 03/2023 | 5 / 18.68 | NC / 17.67 | NC / 30.02 | NaN | NaN | 5 / NTD | NC / 2 |
For each row, I'm trying to apply 3 conditionals:
- if the cell contains number / number, replace that within same df for the text "Division"
- if the cell contains NC / number, replace that within same df for the text "No changes"
- if the cell contains number / NTD, replace that within same df for the text "No ToDo's"
Note that everything will be in the same dataframe, that's just changing the text for the conditions that the code must detect. That said, this should be the expected output:
| Date | Col 1 | Col 2 | Col 3 | Col 3 | Col 4 | Col 5 | Col 6 |
|---|---|---|---|---|---|---|---|
| 09/2023 | 181.70 | Division | 14.40 | 109.00 | NaN | 6 | No ToDo's |
| 06/2023 | 143.60 | 17.00 | 15.30 | 190.05 | NaN | Division | 1 |
| 03/2023 | Division | No changes | No changes | NaN | NaN | No ToDo's | No changes |
My attempt for one of them (condition # 2):
for k in range(0, df.shape[1]):> for m,p in enumerate(df[df.columns[(k)]]): if (p == ("<NC> / ")): df[df.columns[k]][m] = df[df.columns[k]][m].replace(p, 'No changes')Similarly, I applied the above code for the 'number / NTD' (condition #3) and seems to doing well, however, the condition # 1 has been slightly complicated because it needs to be the first one stated in the code (not in the else part of the if condition) and I don't know how to apply the 'if' condition for any number that's before and after the '/'
Any help on that will be appreciated!