-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: pd.Series produces NaN for valid input as per documentation #34534
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
Hi, thanks for your report. Could you please assign a title for this issue? What would you like to achieve with this statement? Your index ist
to get your output or
if your Index should be A,B,C |
Below is the part of doucmentation. indexarray-like or Index (1d) Source: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.html#pandas-series |
The index does override the keys found in the dict. It is not clear to me, whether the data should persist or not. I would assume, that it is tried to match the keys with the index values and fill the remaining keys with NaN. There exist tests which suggest this behavior. Nevertheless, if I am not mistaken we could improve the documentation a bit to clarify the behavior. |
I suppose instead of "override" the documentation could maybe be reworded to say that the Series will be reindexed based on the index argument. I'm not sure though why we would want to specify an index implicitly with dictionary input and then immediately provide a different index in the same call. |
@TomAugspurger has an old PR about clarifying this behavior if you want see if can find the reference there are also several issues about this (likely references from that PR) |
@harry-b-harish, if you pass the index argument, it will surely take the indexes as passed in the argument.
The Output will be: CS Engineering Pandas will automatically take the keys of the dictionary as indexes. When you run the below code
The output will be: 0 Engineering All you can see that pandas has taken default indexes on its own. In your problem pandas Series is creating a Series including the indexes you passed as an argument but when it found that dept is a one-dimensional data with labels. It is like 2-dimensional for it as it has already created the index column(passed as an argument). |
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample
Problem description
pandas series is created by passing dict as input data and also index as additional argument. The indexes are updated but the values are changed to NaN. Whereas if I remove the index argument, it works fine.
Expected Output
CS Engineering
ENG Arts
PHY Science
dtype: object
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.7.5.final.0
python-bits : 64
OS : Windows
OS-release : 10
machine : AMD64
processor : Intel64 Family 6 Model 69 Stepping 1, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_India.1252
pandas : 0.25.3
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 19.3.1
setuptools : 41.2.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.4.2
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.10.3
IPython : 7.11.1
pandas_datareader: None
bs4 : 4.8.2
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : 4.4.2
matplotlib : 3.1.2
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : 1.4.1
sqlalchemy : 1.3.17
tables : None
xarray : None
xlrd : 1.2.0
xlwt : None
xlsxwriter : None
The text was updated successfully, but these errors were encountered: