我有一个数据帧df
,该数据帧是从.csv
文件中读取的,其中包含一些缺失值:
import pandas as pd
df = pd.read_csv('my_file.csv')
df:
Name Age Civil
0 Leonard 30 Engaged
1 Sheldon 31
2 Howard Married
3 Raj 29 Single
如果我检查笔记本中的缺失值,它将返回空字符串,其中
df['Civil'][1]:
' '
type(df['Civil'][1]):
str
如何用NaN
替换空字符串?