I have a dataframe news_count. Here are its column names, from the output of news_count.columns.values:
[('date', '') ('EBIX UW Equity', 'NEWS_SENTIMENT_DAILY_AVG') ('Date', '')
('day', '') ('month', '') ('year', '')]
I need to groupby by year and month and sum values of 'NEWS_SENTIMENT_DAILY_AVG'. Below is code I tried, but neither work:
Attempt 1
news_count.groupby(['year','month']).NEWS_SENTIMENT_DAILY_AVG.values.sum()
'AttributeError: 'DataFrameGroupBy' object has no attribute'
Attempt 2
news_count.groupby(['year','month']).iloc[:,1].values.sum()
AttributeError: Cannot access callable attribute 'iloc' of 'DataFrameGroupBy' objects, try using the 'apply' method
Input data:
ticker date EBIX UW Equity month year
field NEWS_SENTIMENT_DAILY_AVG
0 2007-05-25 0.3992 5 2007
1 2007-11-06 0.3936 11 2007
2 2007-11-07 0.2039 11 2007
3 2009-01-14 0.2881 1 2014
news_count.groupby(['year','month']).NEWS_SENTIMENT_DAILY_AVG.sum()?NEWS_SENTIMENT_DAILY_AVGcolumn. Error message -AttributeError: 'DataFrameGroupBy' object has no attribute 'NEWS_SENTIMENT_DAILY_AVG'df.columns = ['date', 'avg', 'day', 'month', 'year', ...]and so on. If you can do that, please update your dataframe, and try my suggestion in my first comment again.