I have 1 sheet with 2 columns
How can I find repeated rows in 'A' column
Add this rows in dictionary (Key = 'A' value & Value = 'B' value)
import pandas as pd
data = pd.read_excel (r'./1.xlsx')
df = pd.DataFrame(data, columns= ['xcode', 'xyear'])
print (df)
CodePudding user response:
To get duplicates in a dataframe you can use duplicated
:
df["duplicated_flag"] = df.duplicated(subset=['xcode'])
# get the data that is duplicated only
duplicates = df[df["duplicated_flag"]]
# create a dictionary with the tuples of duplicates
result = dict(zip(duplicates["xcode"], duplicates["xyear"]))
CodePudding user response:
thank you , but i need this result