问题
I have this dataframe which includes 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. 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.
Any ideas ? Thanks !
回答1:
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
来源:https://stackoverflow.com/questions/42363235/fill-nan-with-repeated-values