如何使用Python中的pandas从数据框中获取列标题? [英] How do I obtain the column titles from a dataframe using pandas in Python?
本文介绍了如何使用Python中的pandas从数据框中获取列标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在使用pandas,需要列出数据框的列标题。
我尝试过:
我尝试过使用df.columns,其中df是数据帧
这给了我
索引([u'A', u'B',u'C'],dtype ='object')
。
我需要的是['A', 'B','C']
解决方案
你已经拥有它, u
前缀只告诉你字符是Unicode。请参见 2。内置函数 - Python 2.7.13文档 [ ^ ]。
I am currently using pandas and need to list the column titles of a dataframe.
What I have tried:
I have tried using df.columns, where df is dataframe
which gives me
Index([u'A', u'B', u'C'], dtype='object')
.
What I need is ['A', 'B', 'C']
解决方案
You already have it, the u
prefix merely tells you the characters are Unicode. See 2. Built-in Functions — Python 2.7.13 documentation[^].
这篇关于如何使用Python中的pandas从数据框中获取列标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文