-4

Let's say: there is a data frame:

country       Edition     sports       Athletes           Medal  Firstname
Germany          1990    Aquatics  HAJOS, Alfred          gold     Alfred
Germany          1990    Aquatics  HIRSCHMANN, Otto       silver   Otto
Germany          1990    Aquatics  DRIVAS, Dimitrios      silver   Dimitrios
US               2008    Athletics MALOKINIS, Ioannis     gold     Ioannis
US               2008    Athletics HAJOS, Alfred          silver   Alfred
US               2009    Athletics CHASAPIS, Spiridon     gold     Spiridon
France           2010    Athletics CHOROPHAS, Efstathios  gold     Efstathios
France           2010    Athletics CHOROPHAS, Efstathios  gold     Efstathios
France           2010    golf      HAJOS, Alfred          Bronze   Alfred 
France           2011    golf      ANDREOU, Joannis       silver   Joannis 
Spain            2011    golf      BURKE, Thomas          gold     Thomas

can anyone tell me how to assign Firstname of Athletes to new column 'Firstname' in most efficient way? after adding new column df['Firstname']?

loki
  • 976
  • 1
  • 10
  • 22
prabs
  • 81
  • 1
  • 7

1 Answers1

1

For your case:

df['Firstname'] = df['Athletes'].str.split(',\s+').str[1]
Quang Hoang
  • 146,074
  • 10
  • 56
  • 74