Home > Mobile >  Removing all elements execpt the first one in list pandas dataframe
Removing all elements execpt the first one in list pandas dataframe

Time:01-27

I have a pandas dataframe, in which in one column I have a list of hashtags. Now, I would like to delete all elements in that list expect the first one of each row. Is there a way of doing this?

CodePudding user response:

A simple way to do so:

df.hashtags = df.hashtags.map(lambda l: l[:1])
  •  Tags:  
  • Related