I have a DataFrame of the format:
ID Theme Operation Volume
100 Jungle S3 Full
200 Desert S3 Full
302 Cavern S1 Empty
303 Swamp nan Full
400 Jungle S3 nan
600 Desert nan Empty
Where I would like to write a script that iterates through the empty cells and reassigns them from 'nan', and replaces them with a variable NA_ where the _ is a count of how many missing variables they are. So my desired output would be:
ID Theme Operation Volume
100 Jungle S3 Full
200 Desert S3 Full
302 Cavern S1 Empty
303 Swamp NA1 Full
400 Jungle S3 NA3
600 Desert NA2 Empty
When I try to iterate over the df and identify the nan values, for some reason the following did not work.
count = 0
for col in df.colums:
for row in df[col]:
if row == float('nan'):
row = 'NA{}'.format(count)
count += 1
Any ideas why? Or is there a better way to do this that I'm struggling to see?
Thanks :)