简体   繁体   English

如何从excel sheet2中的excel sheet1打印数字并且重复的数字只能打印一次?

[英]How can I print numbers from excel sheet1 that are there in excel sheet2 and that too repeated numbers must print only once?

import pandas as pd
df1=pd.read_excel('excel_data.xlsx')     # This file has list of repeated numbers(1,1,2,3,5,5,9)
df2=pd.read_excel('excel_data2.xlsx')      # This file has list(1,2,3,4,5,6)
df = df2.merge(df1, how = 'inner' ,indicator=False)
print(df)

1- I want to print numbers from excel_data.xlsx that are there in excel_data2.xlsx and that too repeated numbers must print only once.(desired output- 1,2,3,4,5) 1- 我想从 excel_data2.xlsx 中的 excel_data.xlsx 打印数字,并且重复的数字只能打印一次。(所需的输出 - 1,2,3,4,5)

2- I'm getting repeated numbers like (1,1,2,3,5,5) in the output 2- 我在输出中得到重复的数字,如 (1,1,2,3,5,5)

Add a line添加一行

    df = df2.merge(df1, how = 'inner' ,indicator=False)
    df.drop_duplicates(inplace=True)

You say your desired output is (1,2,3,4,5) however 4 doesn't appear in excel_data.xlsx.你说你想要的输出是 (1,2,3,4,5) 但是 4 没有出现在 excel_data.xlsx 中。 The current output minus duplicates seems to be what you're looking for!当前输出减去重复项似乎就是您要找的!

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

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