Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想知道是否可以将 1(或 n)添加到 pandas DataFrame / Series 中的缺失值。
例如 : 1 10 南 15 25 南 南 30
将返回: 1 10 11 15 25 26 27 28 30
谢谢,
使用.ffill+ 的结果groupby.cumcount来确定n
.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