-
-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Description
Code Sample, a copy-pastable example if possible
df1 = pd.DataFrame.from_records([[1,2,3],[4,5,6],[7,8,9]], index=0, exclude=[0])
df2 = pd.DataFrame.from_records([[1,2,3],[4,5,6],[7,8,9]], index=0)
Problem description
In both cases, the data frame has columns 0, 1 and 2. If you use an index of 1, or exclude=[1]
, the columns are (correctly) [0, 2]
.
The issue is caused by the any()
call at https://github.com/pandas-dev/pandas/blob/master/pandas/core/frame.py#L1178 which treats a zero column ID as false. Changing this to if exclude
fixes the problem for me (by running the code to drop columns if the exclude set is not empty).
Output of pd.show_versions()
pandas: 0.21.0
pytest: None
pip: 9.0.1
setuptools: 38.2.4
Cython: None
numpy: 1.13.3
scipy: None
pyarrow: None
xarray: None
IPython: 6.2.1
sphinx: None
patsy: None
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.1.0
openpyxl: 2.4.9
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 1.0b10
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None