I have a dataframe with X rows. For each row, I have the information of the month (value from 1 to 12) and hour (value from 1 to 24) in separate columns

I need to create a heatmap with seaborn in order to display the number of entries crossed with the month/hour.

I do not manage to do it. Any idea how should I proceed ?


1 Answer 1

import numpy as np
import pandas as pd
from numpy.random import RandomState
import seaborn as sns

state = RandomState(0)

df = pd.DataFrame({"month":state.randint(1,12,20),

sns.heatmap(pd.crosstab(df["month"], df["hour"]), cmap ="Reds",linewidths=1);

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.