Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError: "None of [Index(['Year', 'Revenue(mil. USD)'], dtype='object')] are in the [columns]" #5

Open
manujosephv opened this issue Jan 28, 2023 · 1 comment

Comments

@manujosephv
Copy link
Collaborator

manujosephv commented Jan 28, 2023

Posting an issue I received through email:

in Chapter 3, notebook "02-Decomposing Time Series.ipynb", I get an error in the line:

tesla_revenue = pd.read_html("https://en.wikipedia.org/wiki/Tesla,_Inc.")[4][['Year', "Revenue(mil. USD)"]]

Error:

KeyError: "None of [Index(['Year', 'Revenue(mil. USD)'], dtype='object')] are in the [columns]"

In this loaded file there are no columns „Year“ and „Revenue“.

@manujosephv
Copy link
Collaborator Author

Wikipedia has since been updated and now there are more tables and hence the code is breaking.

Two solutions:

tesla_revenue = pd.read_html("https://en.wikipedia.org/wiki/Tesla,_Inc.")[5][['Year', "Revenue(mil. USD)"]]

But this is brittle and may break in the future.

Instead, we can fix the wiki link to an archived one

tesla_revenue = pd.read_html("https://en.wikipedia.org/w/index.php?title=Tesla,_Inc.&oldid=1111822107")[4]

@manujosephv manujosephv pinned this issue Jan 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant