简体   繁体   中英

How to take only index 0 of a list of a pandas dataframe and create a new dataframe?

In resume:

i have a Dataframe like this in python pandas:

Code  Name
13    [Robert, RoBert, robert, robert man]
2     [Barbie, BarBie, barbie, barbie womam]
5     [ShibA, Shiba, Shibba, shiba dog]
100   [HusKYE, huskye, Huskye, huskye dog]

I want to transform it into this:

Code  Name
13    Robert
2     Barbie
5     ShibA
100   HusKYE

How can i do it?

You can use pandas.Series.apply . df['First_Name'] = df['Name'].apply(lambda names: names[0])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM