I am trying to create a function for NaN handling. I would like to always assign the mean of the previous and preceding element for the NaN value.
My idea was something that looks like this
def na_handler(df):
for i in range(1, len(df)):
if i == NaN:
i = ((i-1) + (i+1)) / 2
However this doesnt work, since I dont know how to access the elements in the df properly.
I somehow dont really get the basics of how accessing data in a df works. I have watched some Videos on data handling in python but I always get stuck when I try to solve a problem. If anyone has a good recomendation on where to learn data science with python I would be very thankful. Thanks for any help!