0

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
jfcb
  • 9
  • 4
  • 1
    Hi, please read this: https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples and update your question so we can reproduce your error. Specifically, how can we reconstruct a similar `df` that you have? – Be Chiller Too Oct 27 '21 at 16:32
  • I did the modifications, just let me know if you need something else – jfcb Oct 27 '21 at 17:26
  • You probably need to create a pivot table, similar to the flights example at [the Seaborn heatmap docs](https://seaborn.pydata.org/generated/seaborn.heatmap.html). Something like `analysis_2_df .pivot('hour','day','message')`. Maybe also make your hour column numeric. – JohanC Oct 27 '21 at 17:37
  • Code is updated generating a new pivot table but getting another error shown above – jfcb Oct 27 '21 at 20:58
  • Any suggestion on this?? – jfcb Oct 28 '21 at 00:21
  • Even with your update we can't copy and paste your code and execute it, you need to provide a small portion of code so we can create a similar `df` as you have. – Be Chiller Too Oct 29 '21 at 09:32

0 Answers0