1.Link is "https://www.xyz.{country}/dp/{asin}" 2.I have to pick two things from csv file which country and asin. CSV file contains :
Asin Country
0 1011 de
1 1022 fr
2 1033 de
My question : How can I extract asin and country one by one and make urls like
https://www.xyz.{country}/dp/{asin} --> https://www.xyz.de/dp/1011
https://www.xyz.{country}/dp/{asin} --> https://www.xyz.fr/dp/1022
CodePudding user response:
try this :
lst_url=[]
for index,row in df.iterrows():
country=df.loc[index,'Country']
asin=df.loc[index,'Asin']
url=f"https://www.xyz.{country}/dp/{asin}"
lst_url.append(url)
lst_url
will contain all the url you want
CodePudding user response:
Filter columns by list ['Country','Asin']
, convert to numpy and in for
get scalars passed to f-string
:
df = pd.read_csv(file)
for country, asin in df[['Country','Asin']].to_numpy():
url=f"https://www.xyz.{country}/dp/{asin}"
print (url)
https://www.xyz.de/dp/1011
https://www.xyz.fr/dp/1022
https://www.xyz.de/dp/1033
For list use:
L = [f"https://www.xyz.{country}/dp/{asin}"
for country, asin in df[['Country','Asin']].to_numpy()]
CodePudding user response:
with open(csv_file, 'r') as f:
datas = f.readlines()
for data in datas[1:]:
asin, country = data.split()
print(f'https://www.xyz.{country}/dp/{asin}')
result:
https://www.xyz.de/dp/1011
https://www.xyz.fr/dp/1022
https://www.xyz.de/dp/1033