简体   繁体   中英

How to extract single tag from tags row ? Python Pandas

在此处输入图片说明

3300 rows

I need make new single column with single tag each row

Use DataFrame.explode (pandas 0.25+) with Series.str.strip and Series.str.split column Tags for lists:

df1 = (df.assign(Tags = df['Tags'].str.strip('><').str.split('><'))
         .explode('Tags')
         .reset_index(drop=True))

You have to split and then explode your dataframe.

df['Tags'] = df['Tags'].astype('str')

for i in range(len(df)):
     df.at[i, 'Tags'] = df[i, df['Tags'].strip('><').split('><')]

df.explode('Tags')

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