【发布时间】:2019-03-18 15:56:17
【问题描述】:
我有一个 DataFrame df:
A B
1 dog
cat XX
我一直在尝试创建一个看起来像这样的 pandas DataFrame df_new:
A B type_of_A type_of_B
1 dog int string
cat XX string whateverdtype it may be
我试过了:
df_new["type_of_A"] = [pd.api.types.infer_dtype(i) for i in range(df_new['A'].values)]
但我只得到:
TypeError:只有整数标量数组可以转换为标量 索引
谁能给我一个提示?这是正确的方法吗?
提前非常感谢
【问题讨论】:
标签: python-3.x pandas for-loop types multiple-columns