LIMITED TIME OFFER: 50% OFF OF PREMIUM WITH OUR ANNUAL PLAN (THAT'S $294 IN SAVINGS).
GET OFFER

Python Data Cleaning Basics

[https://app.dataquest.io/m/351/cleaning-and-preparing-data-in-python/6/errors-during-data-cleaning]

Hello all,
I was going through this exercise using the jupyter notebook and i keep coming across the error

ValueError: invalid literal for int() with base 10: 'l'

I used the function provided in the exercise but just changed the variable wording. So I am not sure what’s going on. The code used is ;

import pandas as pd

df = pd.read_csv('artworks.csv')

for i, row in df.iterrows():
    birth_date = row[3]
    death_date = row[4]
    
    birth_date = date_cleaner(birth_date)
    death_date = date_cleaner(death_date)
    
    row[3] = birth_date
    row[4] = death_date
    
df.head()

Please do let me know where I am going wrong. Very thankful for any and all help

1 Like

Welcome to the Community @animus.agbor.

The reason of getting this error is that your code gets input of l string as an argument in int (alphabet cannot be converted into integer). Check your code properly.

Thank you for the reply and the warm welcome,

Do you mean that my function is expecting an integer but instead it’s getting a string?

How do I fix this? I have tried using the str.replace to no avail. I also tried using the regex method, but I’m not too familiar with that so it also failed to work.

import numpy as np
cols = ['EndDate','BeginDate']
df[cols] = df[cols].replace('[^\d.]', '', regex = True).replace('',np.nan).astype(float)

this didn’t work either, unfortunately. Please help

hi @animus.agbor

You might need to check your function date_cleaner. I guess this conversion you are performing over there.

As far as this dataset is concerned, there is not date with literal l in it. for either of the columns Begin and End Date.