I have many pandas dataframe with dates and stock prices like this:
2017-01-04 00:00:00+00:00 103.24
2017-01-05 00:00:00+00:00 103.89
2017-01-06 00:00:00+00:00 102.42
2017-01-09 00:00:00+00:00 102.60
... etc.
What's the best way to filter those pandas by row position?
I was trying something like this, but didn't work.
filter_list = [0, 2]
stock_prices.filter(filter_list)
Thanks.
Use pandas.DataFrame.iloc
for filtering by position.
For example, to extract rows 0 and 2:
res = stock_prices.iloc[[0, 2], :]
The first indexing parameter filters by row, the second by column.
The pandas
documentation describes in detail various ways of indexing and selecting data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With