在系列中的索引处绘图

2024-10-03 06:30:00 发布

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

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

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()执行此操作?你知道吗


Tags: 数据nameindataindexobject序列out
1条回答
网友
1楼 · 发布于 2024-10-03 06:30:00

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

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()

相关问题 更多 >