Numpy / pandas datetimes

In the pandas frame, let's say mydf(the values ​​of which I originally created from stock prices downloaded from Yahoo), I have the following dtypes:

Close               float64
DateTime     datetime64[ns]
High                float64
Low                 float64
Open                float64
Volume              float64

The column DateTimehas both date and time, i.e. 2015-03-20 00:00:28but I want to save only parts of the date i.e. 2015-03-20.

I tried to convert datetime64[ns]to datetime64[D]using mydf['DateTime'].astype('<M8[D]'), but I get an error TypeError: cannot astype a datetimelike from [datetime64[ns]] to [datetime64[D]].

I tried instead mydf['DateTime'].values.astype('<M8[D]'), and it works without error. When I show print(mydf), the components of time are no longer printed.

However, if I do mydf.dtypes, the mapped dtypefor mydf['DateTime']remains the same, and if I try typeof mydf['DateTime'][0], it actually shows that it matters pandas.tslib.Timestamp.

, - , pandas datetime64[ns] pandas.tslib.Timestamp pandas datetime64[ns] datetime64[D]?

, - , pandas datetime64[D]?

p.s. , . . ,

+4
1

YYYY-MM-DD :

mydf.DateTime.map(lambda x: x.date())

dtype object, datetime64[D].

0

All Articles