I have a database of stations’ codes corresponding to stations’ names of India. Which looks like this:
station_code station_name ACND A N Dev Nagar AHA Abhaipur ADTP Adityapur ANDI Adrsh Ngr Delhi SASN Sahibzada Asngr
I am using google API to return nearest railway stations’ names of a given location. I want to know the corresponding station codes of station names returned by google API. I tried this:
import pandas as pd
df = pd.read_csv(“Stations Codes.csv”)
#let stations variable stores value returned by google API
stations = ‘’‘Chandigarh
Sahibzada Ajit Singh Nagar’’’
station_name = stations.split(’\n’)
for i in range(len(station_name)):
if station_name[i] in list(df[“station_name”]):
code = list(df[df[“station_name”]==station_name[i]][“station_code”])
code = “Not Found”
Output: [‘CDG’, ‘Not Found’]
Mostly, this code works well. But google returns full station names and my database has few station names abbreviated.
for example, google returns “Sahibzada Ajit Singh Nagar” but my database has “Sahibzada Asngr”, similarly google returns “Adarsh Nagar Delhi” but my databse has “Adrsh Ngr Delhi”.
I would have used str.contains(string). but, I don’t want to have multiple station names but the best possible one. If it’s not there return nothing. Thank you in advance!