I have two spreadsheets of data which I am trying to check rows from spreadsheet a against values in spreadsheet b and then take a value from spreadsheet b to a.
Here is the example data:
a.CSV:
IDNumber Title
1 Vauxhall Astra Model H 92-93
2 VW Golf MK2 GTI 90-91
3 BMW 1 Series 89-93
b.CSV:
Manufacturer Model Type Year Tag
VW Golf MK2 1990|1991|1993 1000
VW Golf MK2 GTI 1990|1991|1993 1001
VW Golf MK2 1896|1897|1898|1899 1002
Vauxhall Astra Model H 1991|1992|1993|1994 1003
BMW 2 Series 2000|2001|2002 1004
BMW 1 Series 1889|1890|1891|1892|1893 1005
Result I am trying to achieve c.csv:
IDNumber Title Tag
1 Vauxhall Astra Model H 92-93 1003
2 VW Golf MK2 GTI 90-91 1001
3 BMW 1 Series 89-93 1005
My Code:
import pandas as pd
import re
acsv = pd.read_csv('a.csv', sep=",")
bcsv = pd.read_csv('b.csv', sep=",")
for index, row in acsv.iterrows():
title = row['Title']
for i, r in bcsv.iterrows():
if r['Model'] in title:
type = r['type']
if bool(re.search(rf'\b{type} \b', title)):
year = r['Year']
yearSearch = "|".join([x[2:] for x in year.split("|")])
if bool(re.search(rf'\b(?:{yearSearch})\b.*?\b(?:{yearSearch})\b', ebayTitle)):
tag = r['Tag']
acsv['tag'][index] = tag
acsv.to_csv(fileinString, sep=",", index=False)
Currently it returns a few items but not correctly but If i print the information in the loop inside the last if statement it shows it correctly on the screen but is not storing the information right.
I have put all the indicies in place so you can see exactly how it runs and I attempted to build an online run of it to see if it can work but couldnt get that working but may help in answering the question: https://ideone.com/otV6AS
iterrows()even necessary for this? Also, please provide the data in a more convenient format.