Here is a snapshot of the CSV data, file.
I want to replace the null, or 'nan', values with a 0 and replace all other entries with a 1 in the column 'Death Year':
import pandas as pd
import numpy as np
mydata_csv = pd.read_csv('D:\Python\character-deaths.csv',sep = ',',encoding = 'utf-8')
mydata_csv
del mydata_csv['Book of Death']
del mydata_csv['Death Chapter']
if mydata_csv['Death Year'] == np.nan:
mydata_csv['Death Year'] = 0
else:
mydata_csv['Death Year'] = 1
The above code produces the following error:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().