我有熊猫系列:如何扭转姓和名的顺序在熊猫系列
names = pd.Series([
'Andre Agassi',
'Barry Bonds',
'Christopher Columbus',
'Daniel Defoe',
'Emilio Estevez',
'Fred Flintstone',
'Greta Garbo',
'Humbert Humbert',
'Ivan Ilych'])
,看起来像这样:
0 Andre Agassi
1 Barry Bonds
2 Christopher Columbus
3 Daniel Defoe
4 Emilio Estevez
5 Fred Flintstone
6 Greta Garbo
7 Humbert Humbert
8 Ivan Ilych
,我想让它像这样:
0 Agassi, Andre
1 Bonds, Barry
2 Columbus, Christopher
3 Defoe, Daniel
4 Estevez, Emilio
5 Flintstone, Fred
6 Garbo, Greta
7 Humbert, Humbert
8 Ilych, Ivan
有人建议这样的代码,但它没有工作...
names.apply(split)[1]+', ' + names.apply(split)[0]
我选了以下主题,但他们似乎并没有什么,我想无论是:
Pandas DataFrame, how do i split a column into two
pandas: How do I split text in a column into multiple rows?