[英]Unique texts in row in pandas dataframe
I have a text file with text and numerical data in the format shown in the following picture:我有一个包含文本和数字数据的文本文件,格式如下图所示:
I am importing this file using pandas
using the following command:我使用以下命令使用
pandas
导入此文件:
df = pd.read_csv('dum.txt',sep='\t', header=[0,1], index_col=0)
In this file, I want to find the unique texts in the row called Tag
( ['Tag1', 'Tag1', 'Tag1', Tag1, 'Tag5']
) as a python list.在这个文件中,我想在名为
Tag
( ['Tag1', 'Tag1', 'Tag1', Tag1, 'Tag5']
) 的行中找到作为 python 列表的唯一文本。 How can I do it?我该怎么做?
When I use df.columns
, I get this:当我使用
df.columns
,我得到了这个:
>>> df.columns
MultiIndex(levels=[[u'T1', u'T2', u'T3', u'T4', u'T5'],
[u'Tag1', u'Tag5']], labels=[[0, 1, 2, 3, 4], [0, 0,
0, 0, 1]], names=[u'Type', u'Tag'])
In the aforesaid example, how can I get the unique texts in the row called Tag
?在上述示例中,如何获取名为
Tag
的行中的唯一文本? Thanks.谢谢。
用tolist
做levels
df.columns.levels[1].tolist()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.