I have a dataframe df
ID | Price | Region |
---|---|---|
1 | 23 | AUS |
1 | 45 | DXB |
2 | 25 | GER |
2 | 18 | TUN |
I want to write a code in python to get the following output
ID | Price | Region |
---|---|---|
1 | 45 | DXB |
2 | 25 | TUN |
I have tried using pandasql to get the output but it is not giving the output I want
The code I have tried is
import pandas as pd
import pandasql as ps
#to read table
df=pd.read_excel("test.xlsx")
ps.sqldf("select ID, max(Price), Region from df order by ID")
If there is any other code in python itself (without using pandasql) that can get the above output, please let me know