Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何停止在数据透视表中按字母顺序排列月份_Python 3.x_Pandas_Matplotlib_Seaborn - Fatal编程技术网

Python 3.x 如何停止在数据透视表中按字母顺序排列月份

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") 我认为您可以使用以下命令: 定为约会时间?谢谢,这对我来说是

如何停止将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 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)