Нам нужно numeric
столбцы, чтобы иметь возможность вычислять их, в этом случае sum
:
#Example dataframe
df = pd.DataFrame({'date':['2019-01-04', '2019-01-04', '2019-01-03', '2018-12-22', '2018-08-31'],
'replies_count':['46', '143', '64', '154', '50'],
'polarity':[10, 20, 30, 40, 50]})
print(df)
date replies_count polarity
0 2019-01-04 46 10
1 2019-01-04 143 20
2 2019-01-03 64 30
3 2018-12-22 154 40
4 2018-08-31 50 50
Проверить типы столбцов
print(df.dtypes)
date object
replies_count object
polarity int64
dtype: object
Применить groupby
с sum
print(df.groupby('date').sum())
polarity
date
2018-08-31 50
2018-12-22 40
2019-01-03 30
2019-01-04 30
Теперь измените тип столбца replies_count
на int
и сделайте то же самое groupby
с sum
df['replies_count'] = df['replies_count'].astype(int)
print(df.groupby('date').sum())
replies_count polarity
date
2018-08-31 50 50
2018-12-22 154 40
2019-01-03 64 30
2019-01-04 189 30
Как мы видим, столбец включен сейчас.