Pandas按降序绘制x或index_列

2024-05-23 17:09:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我想做一些基于从化学分析导入的csv文件的绘图。所以我导入如下:

In [91]:

df = pd.read_csv('/file_location/Untitled 1.csv', delimiter = '\;', index_col = 'IR')
df

Out[91]:
Sample 1    Sample 2
IR      
300 1   0
400 5   4
500 6   0
600 0   8
4 rows × 2 columns



 In [98]:

df.plot()

好的看起来不错。

按照惯例,我用x轴按降序绘制这类数据。右边最高的数字(不要问我为什么)。所以我重新排序索引列:

In [97]:

df2 = df.sort_index(axis=0, ascending=False, kind='quicksort')
df2
Out[97]:
Sample 1    Sample 2
IR      
600 0   8
500 6   0
400 5   4
300 1   0
4 rows × 2 columns

太棒了!

In [96]:

df2.plot()
Out[96]:

但是当我画出来的时候它看起来是一样的(/sadpanda)

有什么想法吗?


Tags: columns文件csvsamplein绘图dfread