You need to do something like this:
pd.options.mode.chained_assignment = None #suppresses "SettingWithCopyWarning" for index, elem in enumerate(df['ad_requests']): if pd.isnull(elem): df['ad_requests'][index]=df['ad_requests'][index-1]-df['impressions'][index-1]
The warning comes from the fact that we are changing the values ββof the appearance of the data frame, which affects the original data frame. This is what we want to do, however, it really does not concern us.
(Python 2.7.12 and Pandas 0.19.0)
EDIT:
Change the last line of code from
df['ad_requests'][index]=df['ad_requests'][index-1]-df['impressions'][index-1]
to
df.at[index,'ad_requests']=df.at[index-1,'ad_requests']-df.at[index-1,'impressions']
Eliminates the need to suppress any warnings:
for index, elem in enumerate(df['ad_requests']): if pd.isnull(elem): df.at[index,'ad_requests']=df.at[index-1,'ad_requests']-df.at[index-1,'impressions']
Rojan source share