用pandas中的date_range函数代替下列语句:def generate_time_series(start,end,t1,t2): current = start end_item = end time_delta = datetime.timedelta(days=t1,hours=t2) time_series = [current] while current < end_item: next1 = current + time_delta time_series.append(next1) current = next1 return time_series time_hour=generate_time_series(data1.loc[0]['FDT_TIME'],data1.loc[len(data1)-1]['FDT_TIME'],0,1) time_require=[time_hour[160],time_hour[162]] data1_require=data1.drop(data1[(data1['FDT_TIME']<time_require[0])].index) data1_require=data1_require.drop(data1_require[(data1_require['FDT_TIME']>time_require[1])].index) data1_require=data1_require[['FINT_SPEED']]
时间: 2023-06-07 13:11:05 浏览: 98
Python Pandas数据中对时间的操作
可以使用pandas的date_range函数来代替generate_time_series函数,具体代码如下:
import pandas as pd
import datetime
start = data1.loc[0]['FDT_TIME']
end = data1.loc[len(data1)-1]['FDT_TIME']
time_delta = datetime.timedelta(days=0, hours=1)
time_series = pd.date_range(start=start, end=end, freq=time_delta)
time_require=[time_series[160], time_series[162]]
data1_require = data1[(data1['FDT_TIME']>=time_require[0])&(data1['FDT_TIME']<=time_require[1])]
data1_require = data1_require[['FINT_SPEED']]
阅读全文