【问题标题】:Plot at indexes in pandas Series在熊猫系列中的索引处绘图
【发布时间】:2015-03-27 18:25:46
【问题描述】:

我有一个熊猫系列,里面有一些数据:

In [117]: data1.C_TRQENG
Out[117]: 
0         Nm
1       4.85
2      5.339
3      2.552
4     -0.171
5     -0.142 
6      1.218
7     -1.133
8      2.188
9       0.88
10     4.316
11     10.06
12     8.925
13     8.262
14     7.627
...

Name: C_TRQENG, Length: 1230, dtype: object

和另一个系列,该系列中有一些最大值

In [115]: data
Out[115]: 
915     199.571429
1087    173.339207
984     114.696170
27       90.184324
82       80.805341
Name: C_TRQENG, dtype: float64

In [116]: data.index
Out[116]: Int64Index([915, 1087, 984, 27, 82], dtype='int64')

我想在这些索引处绘制原始数据,窗口为正/负 100,以便了解这些点发生的情况。如何使用 plot() 做到这一点?

【问题讨论】:

    标签: python pandas matplotlib


    【解决方案1】:

    使用 pandas 切片为每个索引创建一个窗口,然后绘制它

    nlarge = pct.nlargest(5)
    
    for ind in nlarge.index:
        high = ind + 100 
        low = ind - 100
        window = data.C_TRQENG[low:high]
        window = window.convert_objects(convert_numeric=True)
        window.plot()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-06
      • 2021-12-07
      • 2018-03-25
      • 2013-08-22
      • 1970-01-01
      相关资源
      最近更新 更多