Skip to content

columns sometimes not added to empty dataframe #28871

Closed
@innominate227

Description

@innominate227

Code Sample, a copy-pastable example if possible

import datetime
import pandas as pd

test = pd.DataFrame({'date':[datetime.datetime(2000,1,1)]}).set_index('date')
test = test[0:0].copy()

test['3010'] = None
test['2010'] = None

print(test)

Problem description

The column '3010' is added to the dataframe as expected, but column 2010 does not get added.

Expected Output

Empty DataFrame
Columns: [3010, 2010]
Index: []

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.5.4.final.0
python-bits : 64
OS : Windows
OS-release : 10
machine : AMD64
processor : Intel64 Family 6 Model 85 Stepping 4, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None

pandas : 0.25.1
numpy : 1.17.2
pytz : 2019.3
dateutil : 2.8.0
pip : 9.0.1
setuptools : 36.4.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
openpyxl : None
odfpy : None
gcsfs : None
bottleneck : None
pandas_gbq : None
xarray : None
tables : None
scipy : None
pyarrow : None
xlsxwriter : None
matplotlib : None
sqlalchemy : None
pytables : None
xlwt : None
lxml.etree : None
s3fs : None
xlrd : None
numexpr : None
bs4 : None
fastparquet : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    ConstructorsSeries/DataFrame/Index/pd.array ConstructorsIndexingRelated to indexing on series/frames, not to indexes themselvesNeeds TestsUnit test(s) needed to prevent regressions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions