答案 0 :(得分:1)
一种解决方案是,您可以在使用to_period
方法进行绘图之前修改datetime object
。这是一个示例:
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
#generating some test data
days = pd.date_range('1/1/2000', periods=8, freq='D')
d2 = dict({'price': [10, 11, 9, 13, 14, 18, 17, 19]})
df = pd.DataFrame(d2,index=days)
print(df)
#making join_date a datetime object
#df['join_date'] = pd.to_datetime(df['join_date'])
#setting join_date as index of the dataframe
#df.set_index(['join_date'],inplace=True)
#reducing the datetime object assuming the datetime is index and it is in pandas datetime format
df.index = df.index.to_period("D")
#plotting the heatmap
sns.heatmap(data=df)
plt.tight_layout()
plt.show()
原始出局:
使用to_period
后的最终支出: