如何从标签行中提取单个标签? Python Pandas

How to extract single tag from tags row ? Python Pandas

3300 行

我需要制作新的单列,每行带有一个标签

您必须拆分然后分解数据框。

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

对列表使用 DataFrame.explode (pandas 0.25+) with Series.str.strip and Series.str.splitTags

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