0

I am new to Python and trying to reproduce my R code in python.

I have a pandas dataframe as below

        Date  Volume  CatVolume      RollMean
0 2017-01-01     727          0           NaN
1 2017-01-08     899      36908           NaN
2 2017-01-15     942      37478  24795.333333
3 2017-01-22     846      66147  46844.333333
4 2017-01-29     802      55039  52888.000000
5 2017-02-05     828      47980  56388.666667
6 2017-02-12     781      45807  49608.666667
7 2017-02-19     872      47194  46993.666667

I have identified the index of 'RollMean' column where it has NAN values using

nan_rows = model_Data[model_Data['RollMean'].isnull()]
nan_list = list(nan_rows.index)
print(nan_list)

Output : [0,1]

I want to replace the NAN values by values from 'CatVolume' column. The output I am looking for is

     Date  Volume  CatVolume      RollMean
0 2017-01-01     727          0             0
1 2017-01-08     899      36908         36908
2 2017-01-15     942      37478  24795.333333
3 2017-01-22     846      66147  46844.333333
4 2017-01-29     802      55039  52888.000000
5 2017-02-05     828      47980  56388.666667
6 2017-02-12     781      45807  49608.666667
7 2017-02-19     872      47194  46993.666667

How can this be done?

darkage
  • 857
  • 3
  • 12
  • 22

0 Answers0