-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
pivot_table: precision lost #15091
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
Comments
this is passing thru float
very similar to this
so even though its cast back it will lose precision. not really sure of a great way to prevent this and simulataneously deal with overflow. |
You can use
The thing is that
So not sure there is something to do about it. |
xref to #3707 |
@jreback Do we have a general issue about the precision for int64 algos like mean? As this is not specific to pivot_table, so I would close this. |
oh that whole issue is better anyhow #11199 |
Unfortunately, |
@mstanichenko |
@jorisvandenbossche, I don't really need a multiindex.
I have a set of In [41]: df_ts.columns
Out[41]: Index(['component_id', 'subcomponent_id', 'timestamp_type', 'timestamp_value'], dtype='object') All I want to do is df = df_ts.pivot(index=['component_id', 'subcomponent_id'], colums='timestamp_type', values='timestamp_value').reset_index() |
So with a dummy example, something like this?
where you would expect the output of |
@jorisvandenbossche , sorry but I lost the point. You dummy example looks fine to me. I need the output that In [48]: df = pd.DataFrame({'A':[0,0,0,1,1,1], 'B':[0,1,0,1,0,1], 'C':[0,0,1,1,1,0], 'D':[1,2,3,4,5,6]})
In [49]: df.pivot_table(index=['A', 'B'], columns='C', values='D').reset_index()
Out[49]:
C A B 0 1
0 0 0 1.0 3.0
1 0 1 2.0 NaN
2 1 0 NaN 5.0
3 1 1 6.0 4.0 I never claim that |
My point is that BTW, you can mimick
but if that will help against the precision loss will depend on whether there will be NaNs in the result or not (as it is cast to float anyway in that case) |
Could you please provide a dataframe for which In [53]: df = pd.DataFrame({'A':[0], 'B':[0], 'C':[1], 'D':[2]})
In [54]: df
Out[54]:
A B C D
0 0 0 1 2
In [55]: df.pivot(index=['A', 'B'], columns='C', values='D')
IndexError: index 1 is out of bounds for size 1 |
what would you expected [55] to yield? |
@jreback, I expect @jreback, @jorisvandenbossche, thank you very much for the useful tips. I managed to mimic Nevertheless, it's rather difficult to spot that the data were actually changed by From my limited experience Again, thank you very much for you assistance :-) |
Code Sample, a copy-pastable example if possible
Problem description
Since
value
is a 64-bit integer, we should be able to present it with zero precision loss.Expected Output
Output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.5.2.final.0
python-bits: 64
OS: Linux
OS-release: 3.10.0-514.2.2.el7.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
pandas: 0.18.0
nose: 1.3.7
pip: 9.0.1
setuptools: 28.8.0.post20161110
Cython: 0.23.4
numpy: 1.11.2
scipy: 0.17.0
statsmodels: 0.6.1
xarray: None
IPython: 5.1.0
sphinx: 1.3.5
patsy: 0.4.0
dateutil: 2.6.0
pytz: 2016.2
blosc: None
bottleneck: 1.0.0
tables: 3.2.2
numexpr: 2.5
matplotlib: 1.5.1
openpyxl: 2.3.2
xlrd: 0.9.4
xlwt: 1.0.0
xlsxwriter: 0.8.4
lxml: 3.6.0
bs4: 4.4.1
html5lib: None
httplib2: 0.9.2
apiclient: 1.5.2
sqlalchemy: 1.0.15
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.39.0
The text was updated successfully, but these errors were encountered: