Search code examples
pythonsqlpandasdataframeanalysis

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


Solution

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