Context
Same code for decoding a column with Vehicle Identification Numbers, for one of the libraries i'm getting an error.
Code
import pandas as pd
from vininfo import Vin # COUNTRY AND BRAND
from pyvin import VIN # MODEL AND YEAR
db = pd.DataFrame("VIN": ["3N6PD23W5ZK911765", "MNTACUD40Z0000632", "3N6DD23T9ZK874454"]) # VIN EXAMPLE
db["COUNTRY"] = db["VIN"].map(lambda x: Vin(x).country) # PARSES OK AND RETURNS COUNTRY
db["BRAND"] = db["VIN"].map(lambda x: Vin(x).manufacturer) # PARSES OK AND RETURNS BRAND
db["MODEL"] = db["VIN"].map(lambda x: VIN(x).Model) # ERROR
db["YEAR"] = db["VIN"].map(lambda x: VIN(x).ModelYear) # ERROR
ERROR
AttributeError: 'list' object has no attribute 'Model'
or
AttributeError: 'list' object has no attribute 'ModelYear'
Question
I don't ask for a complete solution because the problem is pretty specific but at this point i'm feeling insecure and any tip is welcome.
Is x
in db["YEAR"] = db["VIN"].map(lambda x: VIN(x).ModelYear)
equal to a single string or is it passing a list to the function?
Let's break the problem in pieces. First, the
db
is a pandas.DataFrame object. Thedb["VIN"]
is a pandas.Series object, as you probably know. You can also verify it withThen, the pandas.Series.map function that you are using takes
arg
as argument that can be type ofdict
or a function (or Series). You give it a function. Then, this function is called for each of the values of the seriesdb["VIN"]
. Let's see what that is.So, for some reason, the
VIN
returns alist
. Why is that? It is because thepyvin.VIN
does not recognize the input. If you add error handling, you'll see:I would suspect that either the VIN code is incorrect, the pyvin has a bug, or the underlying service (NHTSA API) does not recognize the VIN code.