8
A
回答
15
您可以简单地使用df.columns = df.columns.astype(str)
:
In [26]: df = pd.DataFrame(np.random.random((3,6)), columns=[1,2,3,4,5,'Class'])
In [27]: df
Out[27]:
1 2 3 4 5 Class
0 0.773423 0.865091 0.614956 0.219458 0.837748 0.862177
1 0.544805 0.535341 0.323215 0.929041 0.042705 0.759294
2 0.215638 0.251063 0.648350 0.353999 0.986773 0.483313
In [28]: df.columns.map(type)
Out[28]:
array([<class 'int'>, <class 'int'>, <class 'int'>, <class 'int'>,
<class 'int'>, <class 'str'>], dtype=object)
In [29]: df.to_hdf("out.h5", "d1")
C:\Anaconda3\lib\site-packages\pandas\io\pytables.py:260: PerformanceWarning:
your performance may suffer as PyTables will pickle object types that it cannot
map directly to c-types [inferred_type->mixed-integer,key->axis0] [items->None]
f(store)
C:\Anaconda3\lib\site-packages\pandas\io\pytables.py:260: PerformanceWarning:
your performance may suffer as PyTables will pickle object types that it cannot
map directly to c-types [inferred_type->mixed-integer,key->block0_items] [items->None]
f(store)
In [30]: df.columns = df.columns.astype(str)
In [31]: df.columns.map(type)
Out[31]:
array([<class 'str'>, <class 'str'>, <class 'str'>, <class 'str'>,
<class 'str'>, <class 'str'>], dtype=object)
In [32]: df.to_hdf("out.h5", "d1")
In [33]:
0
您可以简单地使用df.columns = df.columns.map(str)
DSM的第一个答案df.columns = df.columns.astype(str)
我的数据框没有工作。 (我得到TypeError:将dtype设置为不支持float64或object的任何东西)
相关问题
- 1. 大熊猫列名列出
- 2. 转换一列从STRING一个月蟒蛇大熊猫到INT
- 3. 如何从熊猫系列中获得最大值和名称?
- 4. 将大熊猫对象拼合到列
- 5. 大熊猫得到从阵列
- 6. 熊猫列名
- 7. 熊猫:将字符串和int的列
- 8. 熊猫加入不同名称的列
- 9. 大熊猫:一列
- 10. 大熊猫 - 多列
- 11. 大熊猫阵列
- 12. 熊猫 - 多列到“列名 - 值”列
- 13. 生成列名重复的大熊猫
- 14. 大熊猫 - 从DF
- 15. 大熊猫从GROUPBY
- 16. 名称添加到大熊猫据帧索引
- 17. 在大熊猫中将列从对象转换为int并进行计数
- 18. 蟒蛇大熊猫 - 转大熊猫的名字意甲成值
- 19. 将熊猫数据框引用/名称返回列表?
- 20. 如何将列名称数组转换为熊猫数据框?
- 21. 大熊猫从从Excel
- 22. 多列从文件到列表中的大熊猫单列
- 23. 功能从列选择大熊猫DF
- 24. 大熊猫一下子从列表
- 25. 大熊猫:得到一系列
- 26. 大熊猫长到宽多列重塑
- 27. 从熊猫列创建angrams名单
- 28. 获取行和列的名称(argmax)在大熊猫数据帧最大入口
- 29. 大熊猫与另一列
- 30. 大熊猫的列标签