Python for DataScience Intermediate


I reproduced the exact code on Jupyter after downloading the dataset artworks as follows (Based on Python for DataScience Intermediate):

for row in moma:
    # remove parentheses from the nationality column
    nationality = row[2]
    nationality = nationality.replace("(","")
    nationality = nationality.replace(")","")
    row[2] = nationality

Unfortunately on DQ it sees no mistake appear but on Jupyter, I have the following error:

TypeError: ‘str’ object does not support item assignment

What should I do? Transform the string into a numeric string?

Hi @a.foucher:

Kindly attach your notebook as per these guidelines. Make sure you have imported the dataset appropriately.

Hello ! Please find the notebook.

Dataquest.ipynb (25.6 KB)

Click here to view the jupyter notebook file in a new tab

The main difference, and the crucial one, is that in the mission we open the file as a list of lists and you have it open as pd.DataFrame. So,

for row in moma:

doesn’t work with a pandas data frame as one could expect with pure python. There’re other methods to iterate over a pandas dataframe, like DataFrame.iterrows(), but one should avoid using them as soon as it’s possible to achieve the same using vecrotization methods.