简体   繁体   English

Python Pandas 从一列和另一列中提取唯一值

[英]Python Pandas extract unique values from a column and another column

I am studying pandas, bokeh etc. to get started with Data Vizualisation.我正在研究 pandas、散景等,以开始使用数据可视化。 Right now I am practising with a giant table containing different birds.现在我正在用一张巨大的桌子练习,里面有不同的鸟。 There are plenty of columns;有很多列; two of those columns are "SCIENTIFIC NAME" and another one is "OBSERVATION COUNT".其中两列是“SCIENTIFIC NAME”,另一列是“OBSERVATION COUNT”。 I want to extract those two columns.我想提取这两列。

I did我做了

df2 = df[["SCIENTIFIC NAME" , "OBSERVATION COUNT"]]

but the problem then is, that every entry is inside the table (since sometimes there are multiple entries/rows due to other columns of the same SCIENTIFIC NAME, but the OBSERVATION COUNT is always the same for the scientific name)但问题是,每个条目都在表内(因为有时由于相同科学名称的其他列存在多个条目/行,但科学名称的观察计数始终相同)

How can I get those two sectors but with the unique values, so every scientific name once, with the corresonding observation count.我怎样才能获得这两个部门但具有独特的价值,所以每个科学名称一次,具有相应的观察计数。

EDIT: I just realized that sometimes the same scientific names have different observation counts due to another column.编辑:我刚刚意识到有时相同的学名由于另一列而具有不同的观察计数。 Is there a way to extract every first unique item from a column有没有办法从列中提取每个第一个唯一项目

IIUC, You can use drop_duplicates : IIUC,您可以使用drop_duplicates

df2 = df[["SCIENTIFIC NAME" , "OBSERVATION COUNT"]].drop_duplicates()

To get counts:要获得计数:

df2 = df.groupby(["SCIENTIFIC NAME" , "OBSERVATION COUNT"])["SCIENTIFIC NAME"].count()

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

相关问题 Pandas:根据另一列的值从一列中提取值 - Pandas: Extract values from a column based on the values from another column Python Pandas 基于另一列的唯一列值计数 - Python Pandas Count of unique column values based on another column 如何从值在列表中的 pandas 列中提取唯一值 - How to extract unique values from pandas column where values are in list Python/Pandas - 识别一列中与另一列中完全相同的唯一值匹配的唯一值 - Python/Pandas - Identify unique values in one column which match the exact same unique values in another column Python pandas dataframe:为另一列的每个唯一值查找最大值 - Python pandas dataframe: find max for each unique values of an another column 另一列中的Python Pandas值 - Python Pandas values from another column 将值从另一列python pandas转移到另一列 - shift values from another column python pandas to another column 对于一列的所有唯一“单词”,从另一列中找到唯一的单元格,然后在python中平均另一列的对应值 - For all the unique 'words" of a column, the find unique cells from another column , then average corresponding values of another column in python 将唯一值从组存储到Pandas中的另一列 - Store unique values from group to another column in Pandas 在 python Pandas 中创建一个具有唯一值的新列 - 不分组 - Create a new column with unique values from another in python Pandas - without grouping
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM