How does pandas remove the hour of the time column and only keep the date

I was bored recently and wanted to play data mining, so I took the [Offline Match] of the Tianchi Newcomer Actual Battle in Tianchi to practice my skills. https://tianchi.aliyun.com/getStart/information.htm?spm=5176.100067.5678.2.2b282b2bAOqNmy&raceId=231522 

Among them, when processing the data, I need to use the date as the index, such as the data of the first 6 days as the training set, and the data of the 7th day as the prediction set. The figure below is the data given by Ali.

Since we need to count the data by day, I temporarily think that the information about the purchase at a few points is useless, and I want to remove it. How to get rid of it?

We can see that the time column is of type object, so we need to convert it first.

Then here are two ways to remove the time:

The second sentence of the above figure is to set the time as the index.

The second method:

all_user['time'] = pd.to_datetime(all_user['time']).dt.date 
This method is slow, please don't try it lightly. For details, please refer to: https://stackoverflow.com/questions/16176996/keep-only-date-part-when-using-pandas-to-datetime 
Then we can split the training set and the prediction set.
train_user = all_user['2014-11-22':'2014-11-27']
train_user_predict = all_user['2014-11-28']
valid_user = all_user['2014-11-29':'2014-12-04']
valid_user_predict = all_user['2014-12-05']
test_user = all_user['2014-12-13':'2014-12-18']
test_user_predict = all_user['2014-12-19']

  








Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325394970&siteId=291194637