简体   繁体   English

如何仅获取熊猫数据框列表的索引 0 并创建新数据框?

[英]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:我在 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 .您可以使用pandas.Series.apply df['First_Name'] = df['Name'].apply(lambda names: names[0])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何仅使用列表理解在 Pandas 数据框中创建新列? - How to create new columns in pandas dataframe with ONLY a list-comprehension? 如何创建一个新列表并将 pandas 数据框写入其中? - How to create a new list and write pandas dataframe to it? 如何创建新的 pandas 列,其中列表值 ==df 索引但列表的长度与原始 dataframe 的长度不同 - how to create new pandas column where list value ==df index but list is a different length to orignal dataframe 如何获取 Python pandas dataframe 列并创建带分隔符的自定义列表 - How to take a Python pandas dataframe column and create a custom list with delimiter 如何创建具有多个自定义索引名称的新 Pandas 数据框? - How to create a new pandas dataframe with multiple, custom index names? 如何在 pandas dataframe 中创建新日期并作为索引插入? - How to create new date and insert as index in pandas dataframe? 如何根据此 Pandas 数据框中的列条件创建新的索引行? - How to create new index lines based on column conditions in this pandas dataframe? 将列表作为带有索引的新行附加到 Pandas DataFrame - Append list to pandas DataFrame as new row with index Pandas:根据数据帧的索引创建一个列表 - Pandas : create a list based on index of a Dataframe 如何在 pandas dataframe 中创建逗号分隔列表作为新列 - How to create a comma seperated list as new column in pandas dataframe
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM