Galat
Galat

Reputation: 477

How to extract single tag from tags row ? Python Pandas

enter image description here

3300 rows

I need make new single column with single tag each row

Upvotes: 0

Views: 533

Answers (2)

Bharath_Raja
Bharath_Raja

Reputation: 642

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')

Upvotes: 0

jezrael
jezrael

Reputation: 862661

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))

Upvotes: 1

Related Questions