我有一个df
df:
  date     shares  symbol  date2
0 20120614  1100   AAT.N   NaN
1 20120615  1100   AAT.N   NaN
2 20120616  1100   AAT.N   NaN
3 20120617  1100   AAT.N   NaN
4 20030405  800    ABT.N   NaN
5 20030406  800    ABT.N   NaN
6 20030407  800    ABT.N   NaN
...
#This is what I want:
df:
  date     shares  symbol  date2
0 20120614  1100   AAT.N   20120615
1 20120615  1100   AAT.N   20120616
2 20120616  1100   AAT.N   20120617
3 20120617  1100   AAT.N   NaN
4 20030405  800    ABT.N   20030406
5 20030406  800    ABT.N   20030407
6 20030407  800    ABT.N   NaN
...
我想用 df.ix[1]['date2'] 替换每个符号的 df.ix[0]['date2'] - 符号在数据帧中发生变化,所以我不能只在整个数据帧中应用它.
我要循环遍历,如果 i 和 i+1 的符号匹配:
df.ix[i]['symbol'] == df.ix[i+1]['symbol']
我打算用日期替换 NaN。
我试过:
df.ix[i]['date2'] = df.ix[i+1]['date']  ##This failed.
然后我尝试了:
a = df.ix[i+1]['date']
df.replace({'date2': i}, a)
###This failed as well
这里有任何建议
1) 完成此任务的最佳过程?
2) 基本问题:如何在 pandas DF 中替换 NaN(甚至是另一个数字)?
谢谢你。