python pandas修改列属性的方法详解
使用astype如下:
df[[column]] = df[[column]].astype(type)
type即int、float等类型。
示例:
import pandas as pd data = pd.DataFrame([[1, "2"], [2, "2"]]) data.columns = ["one", "two"] print(data)
# 当前类型 print("----\n修改前类型:") print(data.dtypes) # 类型转换 data[["two"]] = data[["two"]].astype(int)
修改后类型
print(“―-\n修改后类型”) print(data.dtypes)
相关推荐
jzlixiao 2020-09-15
cjsyrwt 2020-08-14
三石 2020-10-30
roamer 2020-10-29
三石 2020-10-29
wangquannuaa 2020-10-15
wangquannuaa 2020-09-29
wangquannuaa 2020-08-30
三石 2020-08-23
逍遥友 2020-08-21
jzlixiao 2020-08-18
wangquannuaa 2020-08-17
QianYanDai 2020-08-16
jzlixiao 2020-07-29
xirongxudlut 2020-07-20
mmmjyjy 2020-07-16
QianYanDai 2020-07-05
QianYanDai 2020-07-05
june0 2020-07-04