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

TypeError: Int64 when running jb2.pivot_table #17

Open
dougler opened this issue Jun 22, 2022 · 1 comment
Open

TypeError: Int64 when running jb2.pivot_table #17

dougler opened this issue Jun 22, 2022 · 1 comment

Comments

@dougler
Copy link

dougler commented Jun 22, 2022

I have been following the code in your book in jupyter notebook.
There is several places where the code leads to errors. The errors also show up in the github version of the code.
For example:
In the your notebook Chapters 16-30 (page 302 in the physical book)
input 106 and 107 lead to errors. Have they been corrected?

(jb2
 .pivot_table(index='country_live', columns='employment_status',
     values='age', aggfunc='mean')
)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-8-c65017e0f276> in <module>
      1 # run code
----> 2 (jb2
      3  .pivot_table(index='country_live', columns='employment_status',
      4      values='age', aggfunc='mean')
      5 )

~/envs/menv/lib/python3.8/site-packages/pandas/core/frame.py in pivot_table(self, values, index, columns, aggfunc, fill_value, margins, dropna, margins_name, observed, sort)
   8036         from pandas.core.reshape.pivot import pivot_table
   8037 
-> 8038         return pivot_table(
   8039             self,
   8040             values=values,

~/envs/menv/lib/python3.8/site-packages/pandas/core/reshape/pivot.py in pivot_table(data, values, index, columns, aggfunc, fill_value, margins, dropna, margins_name, observed, sort)
     93         return table.__finalize__(data, method="pivot_table")
     94 
---> 95     table = __internal_pivot_table(
     96         data,
     97         values,

~/envs/menv/lib/python3.8/site-packages/pandas/core/reshape/pivot.py in __internal_pivot_table(data, values, index, columns, aggfunc, fill_value, margins, dropna, margins_name, observed, sort)
    185                     #  agged.columns is a MultiIndex and 'v' is indexing only
    186                     #  on its first level.
--> 187                     agged[v] = maybe_downcast_to_dtype(agged[v], data[v].dtype)
    188 
    189     table = agged

~/envs/menv/lib/python3.8/site-packages/pandas/core/dtypes/cast.py in maybe_downcast_to_dtype(result, dtype)
    275     if not isinstance(dtype, np.dtype):
    276         # enforce our signature annotation
--> 277         raise TypeError(dtype)  # pragma: no cover
    278 
    279     converted = maybe_downcast_numeric(result, dtype, do_round)

TypeError: Int64
@mattharrison mattharrison changed the title Code errors TypeError: Int64 when running jb2.pivot_table Jun 22, 2022
@mattharrison
Copy link
Owner

Thanks for reporting @dougler .

I have raised this issue in pandas pandas-dev/pandas#47477

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