There is the following DataFrame:

Column 22 38 26 35 35 54 2 27 14 4 58 20 39 14 55 2 31 35 34 15 28 8 38 19 40 66 28 42 21 18 14 40 27 3 19 18 7 21 49 29 65 21 28.май 

df['Column'].sum() - gives an error:

unsupported operand type (s) for +: 'int' and 'datetime.datetime'

  • one
    what mistake? incomprehensible context of the question - Roman Polshikov
  • everything is working. only I have incorrectly indicated. I have somewhere Nan stands, and somewhere dates .. - Alexander Kudryavtsev
  • hmmm ... what do you expect to get as a sum of dates ??? - MaxU
  • yes i am sorry where are the numbers, where are the dates, where are the empty. in a good way, both the dates and the empty ones should be ignored. leave only numbers. - Alexander Kudryavtsev
  • error traceback , can you give an example of your data, specify the error traceback and also indicate the type of the column column - print(df.dtypes) ? - MaxU

1 answer 1

UPDATE:

 In [143]: df Out[143]: Column 0 22 1 38 2 26 3 35 4 35 5 54 .. ... 37 21 38 49 39 29 40 65 41 21 42 28.май [43 rows x 1 columns] In [144]: df.dtypes Out[144]: Column object dtype: object In [145]: pd.to_numeric(df['Column'], errors='coerce').sum() Out[145]: 1181.0 

Previous answer:

Most likely the column is not a numeric type:

works for numbers:

 In [116]: df = pd.DataFrame({'column':[1,2,np.nan,11,np.nan]}) In [117]: df Out[117]: column 0 1.0 1 2.0 2 NaN 3 11.0 4 NaN In [118]: df['column'].sum() Out[118]: 14.0 

does not work for strings:

 In [119]: df = pd.DataFrame({'column':['1','2',np.nan,'11',np.nan]}) In [120]: df Out[120]: column 0 1 1 2 2 NaN 3 11 4 NaN In [121]: df['column'].sum() ... skipped ... TypeError: Can't convert 'int' object to str implicitly 

Decision:

 In [122]: pd.to_numeric(df['column'], errors='coerce').sum() Out[122]: 14.0