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

Pandas excel output specify column names to write is broken in 1.0.0 #31677

Closed
mikemc3 opened this issue Feb 5, 2020 · 2 comments · Fixed by #31729
Closed

Pandas excel output specify column names to write is broken in 1.0.0 #31677

mikemc3 opened this issue Feb 5, 2020 · 2 comments · Fixed by #31729
Assignees
Labels
Bug IO Excel read_excel, to_excel Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@mikemc3
Copy link

mikemc3 commented Feb 5, 2020

Example code:

df = pd.DataFrame(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]),columns=['col_a', 'col_b', 'col_c'])
excelwritename = '/tmp/Test%s.xlsx' %pd.datetime.now(pytz.timezone('US/Pacific')).strftime('%b%d_%I_%M %p')
with pd.ExcelWriter(excelwritename, engine='xlsxwriter',datetime_format='mmm dd yyyy hh:mm AM/PM') as writer:
df.to_excel(writer,columns=['col_a','col_b'],sheet_name = 'xyz')

Problem description:

specifying column names to output to excel is no longer working in pandas 1.0.0 and it outputs all columns in the df.
Checked different versions of xlsxwriter, but pandas 0.25.3 works fine, while 1.0.0 does not.

Expected Output

It should only output columns that are specified, but it outputs all columns of df

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line]
INSTALLED VERSIONS

commit : None
python : 3.7.4.final.0
python-bits : 64
OS : Darwin
OS-release : 19.2.0
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.0.0
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 20.0.2
setuptools : 45.1.0.post20200127
Cython : 0.29.14
pytest : 5.3.4
hypothesis : 4.54.2
sphinx : 2.3.1
blosc : None
feather : None
xlsxwriter : 1.2.0
lxml.etree : 4.4.2
html5lib : 1.0.1
pymysql : None
psycopg2 : 2.8.4 (dt dec pq3 ext lo64)
jinja2 : 2.10.3
IPython : 7.11.1
pandas_datareader: None
bs4 : 4.8.2
bottleneck : 1.3.1
fastparquet : None
gcsfs : None
lxml.etree : 4.4.2
matplotlib : 3.1.1
numexpr : 2.7.0
odfpy : None
openpyxl : 3.0.3
pandas_gbq : None
pyarrow : None
pytables : None
pytest : 5.3.4
pyxlsb : None
s3fs : None
scipy : 1.3.1
sqlalchemy : 1.3.13
tables : 3.6.1
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : 1.3.0
xlsxwriter : 1.2.0
numba : 0.48.0

@alimcmaster1 alimcmaster1 added IO Excel read_excel, to_excel Bug Regression Functionality that used to work in a prior pandas version labels Feb 5, 2020
@alimcmaster1 alimcmaster1 self-assigned this Feb 5, 2020
@alimcmaster1
Copy link
Member

I see the same on master - taking a look. Will follow up with a PR

cc. @WillAyd

@jbrockmendel is it possible: https://github.com/pandas-dev/pandas/pull/29802/files#diff-428f806ef78207a489c7a688d591fc49L405 is the cause? Surprised we don't have a test for this!

@jbrockmendel
Copy link
Member

is it possible: https://github.com/pandas-dev/pandas/pull/29802/files#diff-428f806ef78207a489c7a688d591fc49L405 is the cause? Surprised we don't have a test for this!

That seems totally plausible. does reintroducing the reindex fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO Excel read_excel, to_excel Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants