I have two parking pandas.Series that are the same size. I also have a class Car (see implementation below). In each row of my parking serie, I have a list of Car object.
for each car in parking1 n-th row, we need to check if the car is present in parking2 n-th row as well.
import pandas as pd
class Car:
def __init__(self, brand, color, mileage):
self.brand = brand
self.color = color
self.mileage = mileage
car1 = Car('toyota', 'black', 1000)
car2 = Car('mercedes', 'white', 3222)
car3 = Car('honda', 'yellow', 2500)
car4 = Car('Wolswagen', 'red', 6000)
carA = Car('mercedes', 'white', 8000)
carB = Car('toyota', 'black', 1000)
carC = Car('ferrari', 'red', 3000)
carD = Car('Wolswagen', 'red', 6000)
parking1 = pd.Series(data=[[car1, car2], [car3, car4]])
parking2 = pd.Series(data=[[carA, carB], [carC, carB]])
def compare_parkings(park1, park2):
diff = list()
""" iterate through cars in parking1, for example, for car1 on row1,
it needs to check whether its in the first row of parking2 as well """
for level1, level2 in zip(parking1, parking2):
level_diff = list()
for car in level1:
if car in level2: #This probably doesn't work
level_diff.append(True)
else:
level_diff.append(False)
diff.append(level_diff)
return diff
diff = compare_parkings(parking1, parking2)
expected_diff = [True, False, False, True]
pass
When I run this script, I get all False for diff
how can I achieve that ?
Thanks