【发布时间】:2020-06-27 08:23:53
【问题描述】:
怎么了?
在 excel 中,我可以使用 number_value 公式将一整列日期或字符串转换为数字。我可以在 Python 中使用我的 dataFrames 上的 pandas 做这样的事情吗?
Tks
【问题讨论】:
-
是的,请参阅
pd.to_numeric或df[col].astype(int) or (float)
标签: pandas
怎么了?
在 excel 中,我可以使用 number_value 公式将一整列日期或字符串转换为数字。我可以在 Python 中使用我的 dataFrames 上的 pandas 做这样的事情吗?
Tks
【问题讨论】:
pd.to_numeric 或 df[col].astype(int) or (float)
标签: pandas
下面的代码应该将字符串值转换为数值。只有在将日期从字符串转换为数字时才需要第一行。
df['col'] = pd.to_datetime(df['col'])
df['col'] = pd.to_numeric(df['col'])
【讨论】: