代码
#!/usr/bin/env Python3
__author__ = '未昔/angelfate'
__date__ = '2019/8/12 12:44'
# -*- coding: utf-8 -*-
import pandas as pd
import numpy as np
data = pd.read_excel(r'E:\python\Study\data_\2.xls')
print(data,'\n')
print(data.info(),'\n')
data['日期'].map(lambda x: x.strftime('%Y-%m-%d'))
data['data'] = data['日期'].map(lambda x: x.strftime('%Y-%m-%d'))
data['time'] = data['日期'].map(lambda x: x.strftime('%H:%M:%S'))
print('数据转换:\n',data,'\n')
data['data']= pd.to_datetime(data['data'])
print(data)
print(data[data['data']==np.datetime64('2019-08-08')],'\n')
结果
E:\Envs\ai\Scripts\python.exe E:/python/Study/BiGData/MY/小实验/提取指定日期数据.py
姓名 日期
0 溜溜 2019-08-08 11:11:11
1 吉吉 2019-08-07 11:11:11
2 哈哈 2019-08-08 13:11:11
3 魏巍 2019-08-08 14:11:11
4 诉讼 2019-08-09 15:11:11
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 5 entries, 0 to 4
Data columns (total 2 columns):
姓名 5 non-null object
日期 5 non-null object
dtypes: object(2)
memory usage: 160.0+ bytes
None
0 2019-08-08 11:11:11
1 2019-08-07 11:11:11
2 2019-08-08 13:11:11
3 2019-08-08 14:11:11
4 2019-08-09 15:11:11
Name: 日期, dtype: object
姓名 日期
0 溜溜 2019-08-08 11:11:11
1 吉吉 2019-08-07 11:11:11
2 哈哈 2019-08-08 13:11:11
3 魏巍 2019-08-08 14:11:11
4 诉讼 2019-08-09 15:11:11
0 2019-08-08
1 2019-08-07
2 2019-08-08
3 2019-08-08
4 2019-08-09
Name: 日期, dtype: object
数据转换:
姓名 日期 data time
0 溜溜 2019-08-08 11:11:11 2019-08-08 11:11:11
1 吉吉 2019-08-07 11:11:11 2019-08-07 11:11:11
2 哈哈 2019-08-08 13:11:11 2019-08-08 13:11:11
3 魏巍 2019-08-08 14:11:11 2019-08-08 14:11:11
4 诉讼 2019-08-09 15:11:11 2019-08-09 15:11:11
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 5 entries, 0 to 4
Data columns (total 4 columns):
姓名 5 non-null object
日期 5 non-null datetime64[ns]
data 5 non-null object
time 5 non-null object
dtypes: datetime64[ns](1), object(3)
memory usage: 240.0+ bytes
None
姓名 日期 data time
0 溜溜 2019-08-08 11:11:11 2019-08-08 11:11:11
1 吉吉 2019-08-07 11:11:11 2019-08-07 11:11:11
2 哈哈 2019-08-08 13:11:11 2019-08-08 13:11:11
3 魏巍 2019-08-08 14:11:11 2019-08-08 14:11:11
4 诉讼 2019-08-09 15:11:11 2019-08-09 15:11:11
姓名 日期 data time
0 溜溜 2019-08-08 11:11:11 2019-08-08 11:11:11
2 哈哈 2019-08-08 13:11:11 2019-08-08 13:11:11
3 魏巍 2019-08-08 14:11:11 2019-08-08 14:11:11
Process finished with exit code 0
pandas 基础。赞