-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
DataFrame.from_dict multilevel dicts with datetime.date objects as keys sets the values as NaN in the DataFrame #19993
Comments
This code path in |
@jreback The issue is that when One way to solve the issue is to parse the keys in |
not sure of the beat place; see how the from_dict path is handled - this should be similar |
@jreback Wend down the pandas/pandas/core/arrays/categorical.py Line 316 in 85817a7
Setting |
@williamkhshea you can't change that as this will break a number of existing behavior. The point is that |
@jreback You can't simply convert the keys in If |
I have a similar issue, using Jupyter Notebook. It's seems to be related to @hodossy post. import pandas as pd
import datetime
concept_list = ['a', 'b', 'c']
date_list = [datetime.date(2018, 10, 8), datetime.date(2018, 10, 9),
datetime.date(2018, 10, 10)]
dictionary = {'John': {'a': {datetime.date(2018, 10, 8): 1, datetime.date(2018, 10, 9): 1,
datetime.date(2018, 10, 10): 1},
'b': {datetime.date(2018, 10, 8): 2,datetime.date(2018, 10, 9): 2,
datetime.date(2018, 10, 10): 2},
'c': {datetime.date(2018, 10, 8): 3, datetime.date(2018, 10, 9): 3,
datetime.date(2018, 10, 10): 3}},
'Alice': {'a': {datetime.date(2018, 10, 8): 1, datetime.date(2018, 10, 9): 1,
datetime.date(2018, 10, 10): 1},
'b': {datetime.date(2018, 10, 8): 2, datetime.date(2018, 10, 9): 2,
datetime.date(2018, 10, 10): 2},
'c':{datetime.date(2018, 10, 8): 3, datetime.date(2018, 10, 9): 3,
datetime.date(2018, 10, 10): 3}},
'Rupert': {'a': {datetime.date(2018, 10, 8): 1, datetime.date(2018, 10, 9): 1,
datetime.date(2018, 10, 10): 1},
'b': {datetime.date(2018, 10, 8): 2, datetime.date(2018, 10, 9): 2,
datetime.date(2018, 10, 10): 2},
'c':{datetime.date(2018, 10, 8): 3, datetime.date(2018, 10, 9): 3,
datetime.date(2018, 10, 10): 3}}}
index_list = [concept_list, date_list]
index = pd.MultiIndex.from_product(index_list, names = ['Concept', 'Date'])
df = pd.DataFrame(dictonary, index = index)
df The output:
Expected output:
|
My solution is Below. example_multilevel_dict = { pd.DataFrame.from_dict(example_multilevel_dict,orient='index') OUTPUT: |
This looks to work on master now. Could use a test
|
take |
Code Sample, from Jupyter notebook
Output:
Problem description
When constructing a DataFrame from a dictionary with date objects from the datetime library, values are set to NaN when using orient='index'. See examples.
Please note that I suppose that using orient='index' should be equal with a transpose.
Expected Output
print(pd.DataFrame.from_dict(example_multilevel_dict , orient='index'))
Output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.6.3.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 142 Stepping 9, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
pandas: 0.22.0
pytest: None
pip: 9.0.1
setuptools: 28.8.0
Cython: None
numpy: 1.14.1
scipy: None
pyarrow: None
xarray: None
IPython: 6.2.1
sphinx: None
patsy: None
dateutil: 2.6.1
pytz: 2018.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
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: