如何在图值列与组之间绘制线条

时间:2019-07-12 01:36:49

标签: python-3.x pandas matplotlib pandas-groupby

我有两列的数据框x2。我正在尝试绘制,但没有得到提示。 数据:

       bins       pp
0     (0, 1]  0.155463
1     (1, 2]  1.528947
2     (2, 3]  2.436064
3     (3, 4]  3.507811
4     (4, 5]  4.377849
5     (5, 6]  5.538044
6     (6, 7]  6.577340
7     (7, 8]  7.510983
8     (8, 9]  8.520378
9    (9, 10]  9.721899

我尝试过此代码结果很好,只是找不到x轴刻度线为空白。我希望箱列值应该在x轴上

x2.plot(x='bins',y=['pp'])

x2.dtypes
Out[141]: 
bins          category
pp             float64

enter image description here

1 个答案:

答案 0 :(得分:0)

以下内容表明在使用0.24.1或更高版本的熊猫时不应出现此问题。

import numpy as np
import pandas as pd
print(pd.__version__)    # prints 0.24.2
import matplotlib.pyplot as plt


df = pd.DataFrame({"Age" : np.random.rayleigh(30, size=300)})

s = pd.cut(df["Age"], bins=np.arange(0,91,10)).value_counts().to_frame().sort_index().reset_index()

s.plot(x='index',y="Age")

plt.show()

结果

enter image description here