I know a question like this has been asked zillion types, but so far I have not been able to find an answer to this question.
I have joined two .csv files together with Pandas and now I would like to add some more columns to the new joined .csv file and the values calculate based on the already available data.
However, I keep getting this error:
"The truth value of a is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()."
Now that obviously seems to be a problem with the data type of my column (which is all integers), but I have not found a (working) way to set that column as integers.
Here is my code:
import pandas
def nscap(ns):
if ns <= 13:
x = ns
elif ns > 13:
x = 13
return x
df_1 = pandas.read_csv("a.csv", sep=';', names=["DWD_ID", "NS"], header=0)
df_2 = pandas.read_csv("b.csv", sep=';', names=["VEG", "DWD_ID"], header=0)
df_joined = pandas.merge(df_1, df_2, on="DWD_ID")
df_joined["NS_Cap"] = nscap(df_joined["NS"])
If i set
df_joined["NS_Cap"] = nscap(20)
the code works fine
I have tried functions like .astype(int) or .to_numeric() but unless I had the syntax wrong, it didn't work for me.
Thanks in advance!

nscapagainst theNScolumn to getNS_Cap, am I correct?df_joined['NS_Cap'] = df_joined['NS'].clip_upper(13)see: pandas.pydata.org/pandas-docs/stable/generated/… there error here is that you're trying to compare an array using an operator that understand scalar values, if you diddf_joined['NS'].apply(nscap)then it should work