-1

我想知道是否可以将 1(或 n)添加到 pandas DataFrame / Series 中的缺失值。

例如 :
1
10

15
25


30

将返回:
1
10
11
15
25
26
27
28
30

谢谢,

4

1 回答 1

0

使用.ffill+ 的结果groupby.cumcount来确定n

df[0].ffill() + df.groupby(df[0].notnull().cumsum()).cumcount()

0     1.0
1    10.0
2    11.0
3    15.0
4    25.0
5    26.0
6    27.0
7    28.0
8    30.0
dtype: float64
于 2019-02-19T20:50:26.877 回答