使用Pandas删除带有特定关键字的空值:NaN值或字符串到浮点的转换问题?

2024-06-30 13:10:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我担心的是使用pandas删除包含“Unknown”关键字的空值。当我上传.csv文件时,这个特定的数据集碰巧有所有带有这个关键字的空值

图片: Data head: 121 values, 8 columns 有关数据集本身的信息如下:

<class 'pandas.core.frame.DataFrame'>
Index: 119 entries, ROMANIA to CZECH REPUBLIC
Data columns (total 7 columns):
authority               119 non-null object
date                    119 non-null object
fine                    119 non-null object
controller/processor    119 non-null object
quoted article          119 non-null object
type                    119 non-null object
infos                   119 non-null object
dtypes: object(7)
memory usage: 9.9+ KB

我已经使用了gdpr_fines.isnull().sum()gdpr_fines.dropna()gdpr_fines = gdpr_fines.drop_duplicates()函数来清除数据,但是没有成功

当我尝试专门筛选'fine'列(fines = gdpr_fines['fine'])并尝试使用float(fines)函数将其从string转换为float时,会出现此问题,但出现以下错误:

TypeError: cannot convert the series to

我不能百分之百肯定的是,pandas根本无法将罚款金额识别为数字,还是因为列中有一些“未知”的NaN值单元格而出错


Tags: columnsto数据函数pandasdataobject关键字