小编Ssz*_*zon的帖子

熊猫以降序排列x或index_column

我想根据化学分析中导入的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()
Run Code Online (Sandbox Code Playgroud)

看起来不错。

按照惯例,我使用x轴按降序绘制这种类型的数据。右边的最高编号(不要问我为什么)。所以我对index-col重新排序:

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
Run Code Online (Sandbox Code Playgroud)

太棒了!

In [96]:

df2.plot()
Out[96]:
Run Code Online (Sandbox Code Playgroud)

但是当我绘制它看起来一样时(/ sadpanda) …

python ipython pandas

3
推荐指数
1
解决办法
4428
查看次数

标签 统计

ipython ×1

pandas ×1

python ×1