python - 处理熊猫中带有逗号的值
问题描述
我有一个包含 8 列的 CSV 文件。在 8 列中,有 2 列的值包含,
例如2,134
对于处理,我需要将数据转换为数字(浮点数)
df = pd.read_csv('data.csv')
df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 90181 entries, 0 to 90180
Data columns (total 8 columns):
user_id 90181 non-null object
location_id 90181 non-null int64
is_shift_accepted 90181 non-null int64
shift_accepted_role 90179 non-null float64
shift_accepted_specialities 89973 non-null float64
distance 90144 non-null object
years_of_experience 80604 non-null float64
shift_id 90181 non-null object
dtypes: float64(3), int64(2), object(3)
memory usage: 5.5+ MB
现在让我们转换成数字
df = df.convert_objects(convert_numeric=True)
df.dtypes
user_id float64
location_id int64
is_shift_accepted int64
shift_accepted_role float64
shift_accepted_specialities float64
distance float64
years_of_experience float64
shift_id float64
dtype: object
现在检查空值 -
# checking for missing values if any
df.isnull().sum()
user_id 89943
location_id 0
is_shift_accepted 0
shift_accepted_role 2
shift_accepted_specialities 208
distance 249
years_of_experience 9577
shift_id 90042
dtype: int64
这里user_id
和它们shift_id
中的值一样,
,给出最高的空计数,尽管它有一个非空值。是因为,
存在于其中吗?预处理这些数据的正确方法是什么?
这是数据的样子
解决方案
推荐阅读
- highcharts - 如果标签与 x 轴不匹配,如何在 Highcharts 中正确绘制 UTC 数据?
- mysql - MySQL按限制排序
- oracle - Oracle 中的 ROWNUM 有替代品吗?
- javascript - 有些东西是未定义的,我不知道为什么
- javascript - 如何使用谷歌浏览器调试 Vue 应用程序
- material-ui - 如何在material-ui对话框顶部显示downshift + popper?
- php - 如何在heredoc中编写循环
- java - 按下弹出窗口中的按钮时从另一个类调用方法
- python - 正态曲线图非...正态
- node.js - Mongodb全文搜索按时间戳排序?