简体   繁体   中英

Fetch rows from a data frame having 2 or more same column values (conditions)

I would like to ask how to pull/display/save in another data frame the IDs of those items whose 2 or more column values match together (Same), example: ID 1 and ID 2 has same Colour and Size value, So I want the output to display only ID 1 and 2 and so on.

Input Data

输入数据

Data Output

Only Displays those rows which match the condition as specified in question

Thanks for your help.

Assuming this is a pandas DataFrame you can filter out text like

df[df.Color  == 'Red' and df.Price > 11]

Might not be the best solution but it works,

dataset=pd.read_csv('Stackoverflow.csv')# Your Dataset
test=dataset[dataset.Color  == 'Red']
test=test[test.Size  == 'Large']
test["IDs"]

代码和输出

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