0

I have data like the following:

Column A
['A','B']
[]

I would like to get the first item from each list so that it would look like this:

First A
'A'
''

I have tried several things, but the most recent is: df['First A'] = df['Column A'].str.list[0]

I get this error: AttributeError: Can only use .str accessor with string values!

It seems that I only get the error when trying to pull the value from the empty lists.

Rachel S
  • 33
  • 4
  • If they are actually lists, then `df['First A'] = df['Column A'].str[0].fillna('')` will give you your desired result, or you can use one of the other methods in the posted duplicate – Nick Apr 22 '23 at 00:35

0 Answers0