添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Hello all, I am trying to do a simple .pivot_table() operation on a dataframe using pandas and I keep getting this error:

TypeError: int() argument must be a string, a bytes-like object or a number, not '_NoValueType'

When running the .py file locally I get no such error, only on pythonanywhere.

I have to say that my research has not returned any results

I am running this snippet

df.pivot_table(index=index,values=values',columns=columns',aggfunc=np.sum,fill_value=0)

index, values, and columns are all strings that refer to the columns of df.

Thank you all

Here's the entire error message I get

    Traceback (most recent call last):
  File "/home/ddjpageant/examination.py", line 260, in <module>
    freq_2020.pivot_table(index='month',values='number',columns='main_new_status',aggfunc=np.sum,fill_value=0)
  File "/home/ddjpageant/.local/lib/python3.8/site-packages/pandas/core/frame.py", line 7028, in pivot_table
    return pivot_table(
  File "/home/ddjpageant/.local/lib/python3.8/site-packages/pandas/core/reshape/pivot.py", line 162, in pivot_table
    table = table.sort_index(axis=1)
  File "/home/ddjpageant/.local/lib/python3.8/site-packages/pandas/core/frame.py", line 5579, in sort_index
    return super().sort_index(
  File "/home/ddjpageant/.local/lib/python3.8/site-packages/pandas/core/generic.py", line 4534, in sort_index
    indexer = get_indexer_indexer(
  File "/home/ddjpageant/.local/lib/python3.8/site-packages/pandas/core/sorting.py", line 77, in get_indexer_indexer
    target._get_codes_for_sorting(), orders=ascending, na_position=na_position
  File "/home/ddjpageant/.local/lib/python3.8/site-packages/pandas/core/indexes/multi.py", line 2327, in _get_codes_for_sorting
    return [
  File "/home/ddjpageant/.local/lib/python3.8/site-packages/pandas/core/indexes/multi.py", line 2328, in <listcomp>
    Categorical.from_codes(level_codes, cats(level_codes), ordered=True)
  File "/home/ddjpageant/.local/lib/python3.8/site-packages/pandas/core/arrays/categorical.py", line 589, in from_codes
    if len(codes) and (codes.max() >= len(dtype.categories) or codes.min() < -1):
  File "/home/ddjpageant/.local/lib/python3.8/site-packages/numpy/core/_methods.py", line 43, in _amin
    return umr_minimum(a, axis, None, out, keepdims, initial, where)
TypeError: int() argument must be a string, a bytes-like object or a number, not '_NoValueType'
              

That makes some sense, but when I run it locally on python I get no errors. It is a simple table like this:

    month | status | number
       1       Completed      44
       1       Potential      14
       1             New       7
       1    Discontinued       1
       2       Completed      40

and I do a simple pivot_table which even when using a fill_value=0 in the pivot_table() I get this error.

My hunch is that there is some version miss-match in pythonanywhere? Some package that relates to pivot_tables is missing?

Sorry, we have had to rate-limit your feedback sending.
Please try again in a few moments... Thanks for the feedback! Our tireless devs will get back to you soon.