I have a pandas DataFrame where one column is the trip distance a taxi has covered. Im using
value_counts() on this column in order to see the most common trip distances.
b = df['trip_distance'].value_counts()
Object b is a pandas Series object. For the sake of completion, the first 5 rows of this Series are
1.00 21815
0.90 18915
0.80 18449
1.10 18263
1.20 17823
Where this means that the most common trip distance is 1, and it appears 21815 times and the same for the rest.
However, if I type b[0:4] instead of printing the 4 first elements of this Series, it finds the element that corresponds to 0 trip distance, and starts printing all the trip distances until it reaches trip distance 4. Of course, if trip distance 4 comes before trip distance 0, it returns an empty Series.
Nevertheless, when I try it on a custom Series
a = pd.Series([3, 1, 2, 3, 4, 4, 5]).value_counts()
Printing a gives
4 2
3 2
5 1
2 1
1 1
and when I try to slice this series, that is, when I type a[0, 3] I get the expected
4 2
3 2
5 1
Does anyone know why this is happening? I know this can be done with iloc/loc, im just curious about why slicing works in one list but not the other.
Thanks in advance.