小编Art*_*nov的帖子

pandas 列中的连续值

我有熊猫df['realize']

time                      realize
2016-01-18 08:25:00     -46.369083
2016-01-19 14:30:00     -819.010738
2016-01-20 11:10:00    -424.955847
2016-01-21 07:15:00     27.523859
2016-01-21 16:10:00     898.522762
2016-01-25 00:00:00    761.063545
Run Code Online (Sandbox Code Playgroud)

哪里time

df.index = df['time']
df.index = pd.to_datetime(df.index)
Run Code Online (Sandbox Code Playgroud)

哪里df['realize']

In: type(df['realize'])
Out: pandas.core.series.Series
Run Code Online (Sandbox Code Playgroud)

我想计算连续值,规则很简单 ( df['realize'] > 0, df['realize'] < 0)

预计输出:

time                      realize    Consecutive
2016-01-18 08:25:00     -46.369083    1
2016-01-19 14:30:00     -819.010738   2
2016-01-20 11:10:00    -424.955847    3
2016-01-21 07:15:00     27.523859     1
2016-01-21 16:10:00     898.522762    2
2016-01-25 00:00:00    761.063545     3
Run Code Online (Sandbox Code Playgroud)

我阅读了有关循环的主题,但没有找到我需要的内容。预先感谢您的帮助。

python dataframe pandas

2
推荐指数
1
解决办法
2135
查看次数

标签 统计

dataframe ×1

pandas ×1

python ×1