简体   繁体   English

用重复值填充nan

[英]Fill nan with repeated values

I have this dataframe which includes nans: 我有这个包含nans的数据框:

     Date
0    7.0  
1    8.0    
2    9.0    
3   10.0     
4   11.0   
5   12.0  
6    1.0  
7    2.0    
8    3.0    
9    4.0    
10   5.0 
11   6.0 
   ...
90   NaN
91   NaN

The Date values are the month number, and I know that on the index 90 it is a 1 but I want to fill the other NaNs with 2, 3 etc until 12 then goes back to 1, 2 and so on. 日期值是月份数,我知道在索引90上它是1,但我想用2,3等填充其他NaN,直到12然后返回到1,2,依此类推。 Lets say it just like in Excel, when you want to fill a column, you put the first values then select them and slide all the way and it fills automatically. 让我们说它就像在Excel中一样,当你想要填充一列时,你把第一个值然后选择它们并一直滑动它自动填充。

Any ideas ? 有任何想法吗 ? Thanks ! 谢谢 !

Just do : 做就是了 :

df.Date=(range(len(df))+df.Date.loc[0]-1)%12+1

Then 然后

In [9]: df.loc[[0,90]]
Out[9]: 
    Date
0    7.0
90   1.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM