如何在 Pandas 中将 DataFrame 某列数据类型转换为字符串

某列转换为字符串:
df['BucketType'] = pd.Series(df['BucketType'], dtype="string")
df['BucketType'] = pd.Series(df['BucketType'], dtype=pd.StringDtype())
df['BucketType'] = df['BucketType'].astype("string")

将某列改为字符串:
df['A'] = df['A'].astype(str)
将某列改为字符串:
df[['B']] = df[['B']].astype(str)
把多列改为字符串:
df[['A','B']] = df[['A','B']].astype(str)
将某列改为字符串:
df['A'] = df['A'].apply(lambda _: str(_))

 

posted @ 2021-12-15 16:46  ivyJ  阅读(15952)  评论(0编辑  收藏  举报