简体   繁体   中英

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:

 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. How can I do it?

When I use df.columns , I get this:

>>> 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 ? Thanks.

tolistlevels

df.columns.levels[1].tolist()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM