-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Adding a new DataFrame row using dict() gives unexpected behaviour #17072
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
@mat2py : Thanks for the issue! I tried your example using Also, if anyone else can reproduce this (cc @jreback ), that would be great to know. |
I can replicate it yes. However the issue doesn't occur if you apply the dict to the df after already having applied the pd.series. You have to recreate the dataframe and only try to add the dict. What you probably did:
What doesn't work:
|
Not on my computer ATM, but can't argue with pictures. Something funny is going on there. PR to patch this is welcome! |
Thanks for the example, this is a duplicate of #16724 |
Code Sample, a copy-pastable example if possible
Link to StackOverflow example
Using pd.series works fine:
But if I try to add a dictionary instead, I get this:
Problem description
Considering that a dataframe can be created using a dictionary, it seems odd that adding to a dataframe using a dictionary would result in shuffled columns when they have been explicitly labeled.
This seems like an unexpected behaviour which, although may not be a bug, doesn't seem like the optimal way of making this process function.
Expected Output
Adding a row to a dataframe using a dictionary which gives column headers results in the same thing as adding a row using pd.series
Output of
pd.show_versions()
pandas: 0.20.2
pytest: None
pip: 9.0.1
setuptools: 33.1.1.post20170320
Cython: None
numpy: 1.12.1
scipy: 0.19.0
xarray: None
IPython: 5.3.0
sphinx: 1.6.1
patsy: None
dateutil: 2.6.0
pytz: 2017.2
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.0.2
openpyxl: 2.4.7
xlrd: 1.0.0
xlwt: 1.2.0
xlsxwriter: None
lxml: 3.7.3
bs4: None
html5lib: 0.999
sqlalchemy: 1.1.5
pymysql: None
psycopg2: None
jinja2: 2.9.5
s3fs: None
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: