用pandas函数代替下列语句: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 07:11:07 浏览: 115
pandas read_excel()和to_excel()函数解析
可以使用pandas.date_range()函数替换generate_time_series()函数来生成时间序列,用pandas.DataFrame.loc[]函数替换data1的切片操作,用pandas.DataFrame.drop()函数替换删除操作,代码如下:
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_hour = pd.date_range(start=start, end=end, freq=time_delta)
time_require = [time_hour[160], time_hour[162]]
data1_require = data1.loc[(data1['FDT_TIME'] >= time_require[0]) & (data1['FDT_TIME'] <= time_require[1])]
data1_require = data1_require[['FINT_SPEED']]
阅读全文