目前,我将以下数据框从Excel导入到pandas中,我想删除基于两列值的重复值。在
# Python 3.5.2
# Pandas library version 0.22
import pandas as pd
# Save the Excel workbook in a variable
current_workbook = pd.ExcelFile('C:\\Users\\userX\\Desktop\\cost_values.xlsx')
# convert the workbook to a data frame
current_worksheet = pd.read_excel(current_workbook, index_col = 'vend_num')
# current output
print(current_worksheet)
| vend_number | vend_name | quantity | source |
| ----------- |----------------------- | -------- | -------- |
CHARLS Charlie & Associates $5,700.00 Central
CHARLS Charlie & Associates $5,700.00 South
CHARLS Charlie & Associates $5,700.00 North
CHARLS Charlie & Associates $5,700.00 West
HUGHES Hughinos $3,800.00 Central
HUGHES Hughinos $3,800.00 South
FERNAS Fernanda Industries $3,500.00 South
FERNAS Fernanda Industries $3,500.00 North
FERNAS Fernanda Industries $3,000.00 West
....
我要删除列quantity和source中的重复值:
查看“数量”和“源”列值:
1.1条。如果供应商的数量在同一行中相等 供应商和源不等于中心,则删除重复的 来自此供应商的行,但行中心除外。在
1.2条。否则,如果同一供应商的另一行中的供应商数量相等,并且没有源中心,则删除重复的行。
期望结果
^{pr2}$到目前为止,我已经尝试了以下代码,但是pandas甚至没有检测到任何重复的行。在
print(current_worksheet.loc[current_worksheet.duplicated()])
print(current_worksheet.duplicated())
我试图找出解决办法,但我在这个问题上挣扎了不少,所以在这个问题上的任何帮助都是非常感谢的。请随意改进问题。在
有一种方法。在
说明
vend_name
和quantity
排序,然后删除标志列。在你可以做两个步骤
相关问题 更多 >
编程相关推荐