*我正在编辑df,因为它在ne1_id 中包含拼写错误
我很难解决以下问题,我非常感谢您对以下问题的帮助或帮助我有一个DataFrame df,看起来像这样:
时间戳 | user_id | ne1_id | ne2_id | attempt_no | ||
---|---|---|---|---|---|---|
0 | 18:11:42.838363 | 1 | 100 | <1>|||
1 | 18:11:42.838364 | 100 | 12346 | |||
2 | 18:11:42.838365 | 100 | 12346 | |||
3 | 18:11:42.83836 | 100 | 12346 | |||
4 | 18:11:45.838365 | 1 | 100 | 2 | ||
5 | 18:11:45.838366 | 100 | 321234 | |||
6 | 18:11:45.838369 | 100 | 321234 | |||
7 | 18:11:46.838363 | 3 | 12 | 3 | ||
8 | 18:11:46.838364 | 12 | 9832 | |||
9 | 18:11:47.838363 | 2 | 12 | 4|||
10 | 18:11:47.83836 | 100 |
def f(x):
last = None
for i in range(len(x)):
if np.isnan(x[i]):
x[i] = last
else:
last = x[i]
return x
df = pd.DataFrame({'x': [1, None, None, 2, None, None, None, 3, None]})
df[['x']].apply(f)
通过在axis=0
上应用该函数,您可以联合处理整个列。