【发布时间】:2018-09-06 09:02:03
【问题描述】:
请查看代码和输出。
我可以知道为什么 *_state 列中的数据类型是 float 而不是 int 以及如何将这些数据类型转换为 int 吗?
谢谢,
代码
print(df_test)
for idx, row in df_test.iterrows():
print(type(row['value']))
df_test.at[idx, row['name'] + '_state'] = row['value']
print(df_test)
输出
消息名称值 0 Door_Started 门 1 1 Light_open 灯 1 输入'int' 输入'int' 消息名称值 Door_state Light_state 0 Door_Started 门 1 1.0 NaN 1 Light_open 灯光 1 NaN 1.0【问题讨论】:
-
*_state 列是按需添加的,所以我想将这些列 dtype 转换为 int
-
知道了。请检查编辑后的答案
标签: python python-3.x pandas