-
-
Notifications
You must be signed in to change notification settings - Fork 19.2k
Description
Pandas version checks
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd
print(pd.DataFrame.from_dict({'good': pd.Series(dict(a=1, b=2)), 'blank': pd.Series()}, orient='index'))
# Expected output:
# a b
# good 1.0 2.0
# blank NaN NaN
# Actual output:
# a b
# good 1 2
print(pd.DataFrame.from_dict({'good': pd.Series(dict(a=1, b=2)), 'blank': pd.Series()}, orient='columns'))
# Output (expected & actual):
# good blank
# a 1 NaN
# b 2 NaNIssue Description
I didn't expect pd.DataFrame.from_dict() to drop rows whose value consists of an empty Series - I expected it to add a row of missing values, just like how it adds a column of missing values when orient='columns'.
Looks like _from_nested_dict() doesn't handle the case when s is empty.
Untested drive-by PR incoming!
Expected Behavior
print(pd.DataFrame.from_dict({'good': pd.Series(dict(a=1, b=2)), 'blank': pd.Series()}, orient='index'))
Expected output:
a b
good 1.0 2.0
blank NaN NaN
Installed Versions
INSTALLED VERSIONS
commit : 9c8bc3e
python : 3.10.12
python-bits : 64
OS : Linux
OS-release : 6.16.3-76061603-generic
Version : #202508231538175856113522.04~171c8de SMP PREEMPT_DYNAMIC Mon S
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_CA.UTF-8
LOCALE : en_CA.UTF-8
pandas : 2.3.3
numpy : 2.2.6
pytz : 2025.2
dateutil : 2.9.0.post0
pip : 22.0.2
Cython : None
sphinx : None
IPython : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : None
lxml.etree : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : None
pyreadstat : None
pytest : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2025.2
qtpy : None
pyqt5 : None