Pandas DataFrame.loc returns Empty DataFrame

by Jason Lee   Last Updated September 12, 2018 05:26 AM

Currently trying to work through some tutorials. Right now I have a pandas Dataframe with stock data. The stock data was taken by reading a csv file, then using df.set_index('timestamp', inplace = True) I set the index to use 'timestamp'. The head is seen here:

 timestamp   open   high    low   close  adjusted_close   volume  dividend_amount  split_coefficient
2018-09-11  74.95  75.69  74.76  75.64           75.64  2225700              0.0                1.0
2018-09-10  75.10  75.21  74.84  74.91           74.91  1774400              0.0                1.0
2018-09-07  75.20  75.20  74.72  75.01           75.01  1804800              0.0                1.0
2018-09-06  74.95  75.55  74.62  75.24           75.24  3058300              0.0                1.0
2018-09-05  75.03  75.42  74.80  74.95           74.95  2418400              0.0                1.0

When I try df.loc['2018-09-05'], it returns the correct row to me. However, when I try to select a range, such as df.loc['2018-09-05':'2018-09-11'], I get an Empty DataFrame returned as so:

Empty DataFrame
Columns: [open, high, low, close, adjusted_close, volume, dividend_amount, 
split_coefficient]
Index: []

Was wondering if anyone could provide any insight as to why this is happening? I would have expected a return of the information between the two dates instead of the empty dataframe. Thanks!



Related Questions


Do not map item to any output using apply()

Updated July 30, 2018 21:26 PM