【发布时间】:2021-09-27 00:31:41
【问题描述】:
我从.csv 文件中读取了一些天气数据作为名为“天气”的数据框。问题是其中一列的数据类型是object。这很奇怪,因为它表示温度。如何将其更改为具有 float 数据类型?我试过to_numeric,但是解析不出来。
weather.info()
weather.head()
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 304 entries, 2017-01-01 to 2017-10-31
Data columns (total 2 columns):
Temp 304 non-null object
Rain 304 non-null float64
dtypes: float64(1), object(1)
memory usage: 17.1+ KB
Temp Rain
Date
2017-01-01 12.4 0.0
2017-02-01 11 0.6
2017-03-01 10.4 0.6
2017-04-01 10.9 0.2
2017-05-01 13.2 0.0
【问题讨论】:
-
我认为看看为什么这是一个对象可能会有所回报。该专栏有什么不寻常的地方吗?
-
我建议添加
pandas标志并将其添加到描述中,因为它与普通 Python 无关。 -
@WillemVanOnsem 这是我做的第一件事!这是一个简单的 csv 文件。这些数字看起来和雨柱没什么不同……