How to reverse the order of first and last name in a Pandas Series

前端 未结 4 900
太阳男子
太阳男子 2021-01-24 16:42

I have a pandas series:

names = pd.Series([
\'Andre Agassi\',
\'Barry Bonds\',
\'Christopher Columbus\',
\'Daniel Defoe\',
\'Emilio Estevez\',
\'Fred Flintstone\         


        
4条回答
  •  情深已故
    2021-01-24 17:02

    Use .map combined with string methods like below:

    names.map(lambda s: s.split()[1] + ', ' + s.split()[0])
    

提交回复
热议问题