【pandas中一列含有多种数据类型的转换:科学计算法转浮点数、字符映射】教程文章相关的互联网学习教程文章

pandas中一列含有多种数据类型的转换:科学计算法转浮点数、字符映射【代码】

import pandas as pd import redef getNum(x):"""科学计数法和字符转浮点数"""if re.findall(r‘\d+\.\d+E\+‘,x):return"%.f" % float(x)elif x=="C":return 1else:return xdf = pd.DataFrame({"x":[2030,1.11002E+11,2030,1.11002E+11,"C"]})df["x"] = df["x"].astype("str")df["x"] = df["x"].apply(getNum)df["x"] = pd.to_numeric(df["x"])df["x"] = df["x"].astype("int64") 原文:https://www.cnblogs.com/wzdLY/p/9885877....