-
-
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
pivot_table returns a Series instead of a DataFrame depending upon the datatype of the values parameter #4371
Comments
Hi @vijaymukhi712, Thanks for the report. Can you please post a minimal reproducible example, meaning that anyone who wants to could load your code into Python and read in a data set that illustrates the issue? It doesn't have to be the data set you found the issue with, but that's okay if you want too. The issue will get resolved much faster if you do this. Thanks. |
I am sorry for not being clear earlier. I have created the smallest csv, a.csv file that shows the anomaly. The data set that I originally worked with was over 80 MB, so no point posting it. As the example above shows why would changing the data type of the values parameter from a string to an array change the data type of the returned object from a Series to a DataFrame. That is the basic question I am asking. My example works with any data set that has two columns and a minimum of one row. |
@vijaymukhi712 , when @cpcloud asked for a minimal reproducible example, something like I think that In [13]: type(df['State'])
Out[13]: pandas.core.series.Series
In [14]: type(df[['State']])
Out[14]: pandas.core.frame.DataFrame Here the outer square brackets is the So you're assumption here
was faulty. Sometimes we do pass arrays with single values. |
@TomAugspurger nice explanation |
Tom, thanks for the insight, never looked at that way. |
My python code looks like
My question is why would a change in the datatype of the values parameter return a DataFrame instead of a Series. After all we use an array only if we have to pass multiple values.
Thank You.
Vijay Mukhi
The text was updated successfully, but these errors were encountered: