I am working with a power consumption dataset in Pandas that includes ZIP codes as a column, but the datatype for this column is an integer in the original CSV file. I'd like to change this column to a string/object datatype, and here's what I've done so far:
df = pd.read_csv('...kWh_consumption_by_ZIP.csv')
df.head()
The resulting dataframe head looks like this:
As mentioned above, when I check df.dtypes, I see that ZIP is listed as int64 data type, so I run the following code to overwrite the existing series and change it to an object data type:
df['ZIP'] = df.ZIP.astype(object)
Everything looks good when I check the df.ZIP series (at least, it looks good to the naked eye):
But when I check the length of each row in the series using the len function:
df.ZIP.str.len()
...the resulting series just returns NaN for each row (see screenshot below).
Does anyone know why this is this happening? Thanks in advance for the help.


