I have a Pandas dataframe that was generated by fetching data from a KDB database, using QPython.
First, the Date column is returned as a strange dtype: dtype('<M8[ns]')
df = conn.sync("select Date, Open, High, Low, Close from stocktable", pandas=True)
df["Date"].dtype
# dtype('<M8[ns]')
However, when I inspect the contents of the column, the bottom row displays the dtype as datetime.
0 2017-04-17
1 2017-04-13
2 2017-04-12
3 2017-04-11
4 2017-04-10
5 2017-04-07
6 2017-04-06
7 2017-04-05
8 2017-04-04
9 2017-04-03
10 2017-03-31
11 2017-03-30
...
3180 2004-08-27
3181 2004-08-26
3182 2004-08-25
3183 2004-08-24
3184 2004-08-23
3185 2004-08-20
3186 2004-08-19
Name: Date, dtype: datetime64[ns]
Also, method last()
is not working correctly. I ask for the last 5 months worth of data, but all of the data is returned.
# Expected to only return last 5 months of data, but returns it all.
df.set_index("Date").last("5M")
How do I get the last rows of this DataFrame?