Hi I Have an issue with output with heatmap
df2 = df.groupby(['hour', 'day'], as_index=False)["message"].count()
df2 = df2.dropna()
df2.reset_index(drop = True,inplace = True)
### Analysing on which time group is mostly active based on hours and day.
analysis_2_df = df.groupby(['hour', 'day'], as_index=False)["message"].count()
### Droping null values
analysis_2_df.dropna(inplace=True)
analysis_2_df.sort_values(by=['message'],ascending=False)
day_of_week = ['Lunes', 'Martes', 'Miercoles', 'Jueves', 'Viernes', 'Sabado', 'Domingo']
analysis_2_df
plt.figure(figsize=(15,8))
heatmap(analysis_2_df.pivot(index='day', columns='hour',values='message'),
x=analysis_2_df['hour'],
y=analysis_2_df['day'],
size_scale = 500,
size = analysis_2_df['message'],
y_order = day_of_week[::-1],
color = analysis_2_df['message'],
palette = sns.cubehelix_palette(128)
)
plt.show()
And I am getting this issue:
AttributeError: 'QuadMesh' object has no property 'x'
an example of analysis_2_df dataframe is:
hour day message
0 00 Domingo 11
1 00 Jueves 6
2 00 Martes 1
3 00 Miercoles 5
4 00 Sabado 29
Example of "df":
date time name message hour
0 2020-12-18 22:18:46 Vero UV creó el grupo “Tranquilo el Perro”\n 22
1 2020-12-18 22:18:47 Vero UV te añadió\n 22
2 2020-12-18 22:19:20 Ryudrigo 22
3 2020-12-18 22:19:29 Vero UV cambió el ícono de este grupo\n 22
datatypes of df:
date datetime64[ns]
time object
name object
message object
hour object
day object
dtype: object
##Updated answer:
Do you mean something like that??
analysis_2_df.pivot(index='day', columns='hour',values='message')
hour 00 01 02 04 06 07 08 09 10 11 ... 14 15 16 17 18 19 20 21 22 23
day
Domingo 11.0 3.0 3.0 NaN NaN 2.0 39.0 73.0 181.0 275.0 ... 96.0 188.0 147.0 262.0 179.0 283.0 349.0 541.0 301.0 41.0
Jueves 6.0 NaN NaN NaN 20.0 41.0 187.0 405.0 367.0 168.0 ... 412.0 284.0 95.0 92.0 172.0 175.0 303.0 471.0 244.0 46.0