Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sum ignoring strings in pandas dataframe [duplicate]

I am using Pandas to make a DataFrame. However some parts of the DataFrame contain a string. how can I ignore these strings in the sum when summing along the rows of the data frame?

df["sum"] = df.sum(axis=1)
like image 610
kitchen800 Avatar asked Dec 30 '22 15:12

kitchen800


1 Answers

Use the numeric_only flag:

df.sum(axis=1, numeric_only=True)
like image 110
iacob Avatar answered Jan 15 '23 23:01

iacob