Assume we have a dataframe and we are interested in 1 column in order to create a new one. So let's deal with that column only. That column has the following format
df
A
n.a
0.74
0.3
1
n.a
...
I want to create a new column that:
- whenever the value in the column A is n.a. OR smaller than 1 then set my new column equal to a variable that I have (which is str)
- If the value is 1 then it should fill n.a.
So in our previous example the dataframe should look something like this
A New col
n.a 15/2/2022
0.74 15/2/2022
0.3 15/2/2022
1 n.a.
n.a 15/2/2022
...
I tried the following
df['New col'] = 'n.a.'
if df['A']!='n.a.':
if df['A']< 1:
df['New col']=date
I am sure this is not the optimal or even a good way to do it. However, I get the following error
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
which I do not understand why