0

I am using the pivot_table function with str_date( date converted to string using strftime) as the index and the polarity column as the column header, and the same polarity column is being used to produce aggregated values( count). Original data

temp_df2 = temp_df[['str_date','polarity','user']]
sent_pvt = pd.pivot_table(temp_df2, index='str_date', columns='polarity', aggfunc='count')

Output: The resulting pivot_table shows the user label above the column names. I can't figure out a way to remove this label. If i use 'polarity' as columns and values it generates an error . I can work around this if I add another column to the original data with all values set 1. I can use this column to sepecify the values argument in pivot_table function. But is there a more convenient way to use the same column for aggregation and column headers?

avg_ali
  • 1
  • 1
  • need `sent_pvt = pd.pivot_table(temp_df2, index='str_date', columns='polarity', values='user',aggfunc='count')` – jezrael Oct 18 '22 at 07:13

0 Answers0