Python 3.x 如何停止在数据透视表中按字母顺序排列月份
如何停止将csv中按时间顺序排列的数据转换为按字母顺序排列的数据(如我当前的绘图)。这是我正在使用的代码:Python 3.x 如何停止在数据透视表中按字母顺序排列月份,python-3.x,pandas,matplotlib,seaborn,Python 3.x,Pandas,Matplotlib,Seaborn,如何停止将csv中按时间顺序排列的数据转换为按字母顺序排列的数据(如我当前的绘图)。这是我正在使用的代码: import seaborn as sns df = pd.read_csv("C:/Users/Paul/Desktop/calendar.csv") df2 = df.pivot("Month", "Year", "hPM2.5") ax = sns.heatmap(df2, annot=True, fmt="d") 我认为您可以使用以下命令: 定为约会时间?谢谢,这对我来说是
import seaborn as sns
df = pd.read_csv("C:/Users/Paul/Desktop/calendar.csv")
df2 = df.pivot("Month", "Year", "hPM2.5")
ax = sns.heatmap(df2, annot=True, fmt="d")
我认为您可以使用以下命令:
定为约会时间?谢谢,这对我来说是解决问题的一种方法。
import pandas as pd
import seaborn as sns
df = pd.DataFrame({'Month':['January','February','September'],
'Year':[2015,2015,2016],
'hPM2.5':[7,8,9]})
print (df)
Month Year hPM2.5
0 January 2015 7
1 February 2015 8
2 September 2016 9
cats = ['January','February','March','April','May','June',
'July','August','September','October','November','December']
df['Month'] = df['Month'].astype('category',
ordered=True,
categories=cats)
df2 = df.pivot("Month", "Year", "hPM2.5")
sns.heatmap(df2, annot=True)