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

Valeu Error for In [10] #8

Open
BrewerCPA opened this issue Feb 27, 2020 · 3 comments
Open

Valeu Error for In [10] #8

BrewerCPA opened this issue Feb 27, 2020 · 3 comments

Comments

@BrewerCPA
Copy link

I received a Value Error when attempting to run the code. Any Suggestions?

ValueError Traceback (most recent call last)
in
3 Census[key] = Census[key][['State','Population']]
4 Census[key].loc[:,'Population']=Census[key].loc[:,'Population'].apply(
----> 5 lambda s: int(re.sub(r'[.*','', str(s)).replace(',','')))
6 display(Census[key].head(8))

~\Anaconda3\lib\site-packages\pandas\core\series.py in apply(self, func, convert_dtype, args, **kwds)
3846 else:
3847 values = self.astype(object).values
-> 3848 mapped = lib.map_infer(values, f, convert=convert_dtype)
3849
3850 if len(mapped) and isinstance(mapped[0], Series):

pandas_libs\lib.pyx in pandas._libs.lib.map_infer()

in (s)
3 Census[key] = Census[key][['State','Population']]
4 Census[key].loc[:,'Population']=Census[key].loc[:,'Population'].apply(
----> 5 lambda s: int(re.sub(r'[.*','', str(s)).replace(',','')))
6 display(Census[key].head(8))

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

@AntonMu
Copy link
Owner

AntonMu commented Feb 27, 2020

That's strange - did you parse the data again or did you use the provided data?

It's possible that wikipedia changed their page layout and some modifications are needed.

Did you run all cells in the same order (top to bottom)?

The line it is erroring out on is supposed to delete the footnotes ([1]) at the end of the number and delete all ,. For instance, 123,123[4] gets turned into '123123'. Hope this helps while debugging.

Because your error string ('101130]') still has ] in it, it means that it wasn't all taken away. I would print the number it is failing on to see what is going on.

@BrewerCPA
Copy link
Author

I did parse the data. I will look at it again.
I am still relatively new to Python, so I like to attempt interesting data science projects like yours and use them to learn. So, it could definitely be my lack of knowledge.
Thanks for your help and for the original work you did.

@AntonMu
Copy link
Owner

AntonMu commented Mar 2, 2020

Ok hope it works out! And happy experimenting with Python.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants