![](/img/trans.png)
[英]Out of memory when DataFrame.resample() is called in pandas on small dataset
[英]How do I stop pandas dataframe.resample('T') from automatically adding extra indexes to dataframe?
我正在嘗試將具有分鍾數據的數據幀下采樣到5分鍾的箱中。 這是我目前的代碼:
df = pd.read_csv('stockPrices/closingPrices-apr3.csv',index_col='date',parse_dates=True)
df['close'] = df['close'].shift()
df5min = df.resample('5T').last()
print(df5min.tail())
csv文件的鏈接位於: https : //drive.google.com/file/d/1uvkUaJwrQNsmte5IQIsJ_g5GS8RjVd8B/view? usp =sharing
輸出應該在2019-04-03 14:40:00停止,因為最后一個值是14:48:00,並且從14:45-14:49開始的5分鍾箱是不可能的。 但是,我得到了以下我的csv文件中不存在的日期時間索引值:
2019-04-03 14:45:00 286.35
2019-04-03 14:50:00 286.52
2019-04-03 14:55:00 286.32
2019-04-03 15:00:00 286.45
2019-04-03 15:05:00 280.64
到目前為止,我能找到的唯一解決方案是使用以下代碼,但是之前幾天的所有數據都會在14:40被切斷:
df5min = df.resample('5T').last().between_time(start_time='9:30',end_time='14:40')
對此有任何幫助表示贊賞。
解決方案將產生一個你可能不想要的行4/3/2018 15:05
df = pd.read_csv('./closingPrices-apr3.csv', index_col='date',parse_dates=True)
df.sort_index(inplace = True)
df = df.shift(5)
df_5min = df.resample('5T').first()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.