I'm just getting started in pandas and found myself a bit stumped by the result of this code.
s = pd.Series([1,2,3,4,5],['a','b','c','d','e'])
print (s[s > s.median()])
A series object, with data and indices greater than the median of s, is returned. How is a series object returned when it's supplied a series object as an index? Why doesn't this return a type error?
another example, why does s[s-2] return a series with the last index moved to the top? I don't understand what is going on behind the scenes here. could someone help me understand?
https://stackoverflow.com/questions/66684172/what-is-happening-when-one-provides-a-pandas-series-object-as-an-index-to-anothe March 18, 2021 at 11:05AM
没有评论:
发表评论