Home > Blockchain >  PYTHON USING PANDAS LIBRARY TO GET RECORD:--
PYTHON USING PANDAS LIBRARY TO GET RECORD:--

Time:07-18

A table in the database containing STATION and CITY. I just want RESPECTIVE STATION for a list of CITY NAME in python using the panda's library.

df=pd.DataFrame(pd.read_sql('SELECT * FROM REGION', conn)) print(df)

enter image description here

CodePudding user response:

try this for example

your dataframe is

     city  citycode
  0  Karan        68
  1  Rohit        22
  2  Sahil        21
  3  Aryan        24

and you want to extract citycode for Karan

df.loc[df['city'] == 'Karan']['citycode']

should do the trick

CodePudding user response:

Like this?

filtered = df[df['CITY'] == 'Paris']['STATION'].item()

If is not, you should provide more info

  • Related