You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In sample above I call pivot_table with columns='c' (just one column) so I expect pivot_table to return DataFrame with Index-ed columns, not MultiIndex-ed.
More examples:
I did some research to understand similar cases. Here is a bunch of examples you can find useful.
df2 defined as Empty DataFrame using pd.DataFrame(). df3.columns in this case is Index (makes sense).
For Empty DataFrame with dtype=objectpivot_table returns DataFrame with Index-ed columns (as expected)
For non-empty DataFramepivot_table returns DataFrame with Index-ed columns (as expected)
For Empty DataFrame with numeric dtypepivot_table returns DataFrame with MutiIndex-ed columns (I suppose it’s a bug)
Code Sample, a copy-pastable example if possible
Problem description
df3.columns
isMultiIndex
In sample above I call
pivot_table
withcolumns='c'
(just one column) so I expectpivot_table
to returnDataFrame
withIndex
-ed columns, notMultiIndex
-ed.More examples:
I did some research to understand similar cases. Here is a bunch of examples you can find useful.
df2
defined asEmpty DataFrame
usingpd.DataFrame()
.df3.columns
in this case isIndex
(makes sense).df2
defined asdf1.loc[df1['a'] == 0]
.df3.columns
in this case isIndex
(makes sense too).df2
defined asEmpty DataFrame
withdtype=Int64
.df3.columns
in this case isMultiIndex
(and this not makes sense at all, what is the difference?).df2
defined as not emptyDataFrame
. Call ofpivot_table
returnIndex
-edDataFrame
(and this makes sense again).My assumptions:
For
Empty DataFrame
withdtype=object
pivot_table
returnsDataFrame
withIndex
-ed columns (as expected)For non-empty
DataFrame
pivot_table
returnsDataFrame
withIndex
-ed columns (as expected)For
Empty DataFrame
with numericdtype
pivot_table
returnsDataFrame
withMutiIndex
-ed columns (I suppose it’s a bug)Any insights?
Expected Output
Output of
pd.show_versions()
pandas: 0.23.4
pytest: 3.1.2
pip: 9.0.1
setuptools: 36.4.0
Cython: 0.28.5
numpy: 1.15.2
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: 6.4.0
sphinx: None
patsy: None
dateutil: 2.7.3
pytz: 2018.5
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.2.2
openpyxl: None
xlrd: 1.1.0
xlwt: None
xlsxwriter: 1.0.5
lxml: None
bs4: 4.6.3
html5lib: 1.0.1
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: