You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I call reset_index on a Series object with arguments inplace=True, it does not work. See the code example below. Am I missing something here? (I am using "0.9.0", checked with pandas.version)
ts_a=pandas.Series([1]*3+[2]*3+[3]*4, range(10))
ts_b=pandas.Series([2]*3+[3]*3+[1]*4, range(10))
ts_c=pandas.Series(numpy.random.randn(10), range(10))
df=pandas.DataFrame({"A": ts_a, "B": ts_b, "C":ts_c})
df=df.set_index(['A', 'B'])['C'] # I select column C here to have a Series object# print df# A B#1 2 1.032# 2 0.139# 2 -0.708#2 3 -1.268# 3 0.138# 3 0.497#3 1 0.973# 1 -0.634# 1 -0.112# 1 -0.997# now let's reset index 'B': inplace does not work?df.reset_index('B', inplace=True)
# print df# A B#1 2 1.032# 2 0.139# 2 -0.708#2 3 -1.268# 3 0.138# 3 0.497#3 1 0.973# 1 -0.634# 1 -0.112# 1 -0.997# when copied, it does workdf=df.reset_index('B')
# print df# Name: C# B C# A #1 2 1.032#1 2 0.139#1 2 -0.708#2 3 -1.268#2 3 0.138#2 3 0.497#3 1 0.973#3 1 -0.634#3 1 -0.112#3 1 -0.997
The text was updated successfully, but these errors were encountered:
Here df is a Series but df.reset_index('B') is a DataFrame.
There's no way to turn df from a Series into a DataFrame so inplace for Series only takes effect if "drop=True" and the result stays a Series.
Alright, I understand now. So I guess it is a choice not to convert a Series object to a DataFrame object.
But why does a DataFrame object get converted to a Series object when I just select 1 column? For example if df is a DataFrame object, then df["A"] would give a Series object, right? This made me think that reset_index would convert a Series object to a DataFrame object.
When I call reset_index on a Series object with arguments inplace=True, it does not work. See the code example below. Am I missing something here? (I am using "0.9.0", checked with pandas.version)
The text was updated successfully, but these errors were encountered: