Data Analysis with Python - Data Analysis Example B

Tell us what’s happening:

Why I getting this error when I run the code I don’t know what to do

NameError Traceback (most recent call last)
in <cell line: 1>()
----> 1 sales = pd.read_csv(
2 ‘data/sales_data.csv’,
3 parse_dates=[‘Date’])

NameError: name ‘pd’ is not defined

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36

Challenge Information:

Data Analysis with Python - Data Analysis Example B

1 Like

have you imported pandas? you need to import pandas with pd as alias

import pandas as pd

I’ve imported pandas and still got error

you need to run the cell in which there is written import pandas as pd

Can you teach step by step I don’t really know what to do

Please show a screenshot of your code and error

Are you working locally or on google collab? Share the notebook if possible.

It is already 1 step, it’s that one line of code:

The error is ‘pd’ is not defined. This is defining pd

Screenshot 2024-06-14 204807

Here also the error

I think there should be a little checkmark in the top right of each of those cells once you’ve run them. It looks like they have not been run.

did you run the block of code where you import numpy, pandas and matplotlib?
if they are in different blocks you need to execute the first one first, then the second.

I actually did that earlier

Try running them again, top then bottom. In your example the bottom frame has a “1”, which means it was run first.

Run the top, then the bottom.

Is this what you talking about? Sorry I could not understand properly

No, not really. I was just giving you an example of how each cell gets a number in the order it was run. You need to run them in order.

Go back to your original code. Run the import cell first. Then run the next cell. The import cell should get a [1] indicating it was run first. The second cell should have a [2] indicating it was run second.

as you can see in this screenshot, when you use print(pd) you dont get the error that pd is not defined, because you ran the block of code that imports pandas as pd before you ran the print(pd) one.
you should do the same with your challenge.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.