Enhance trading workflow with new order flow management
- Added dingdanliu_nb_mflow for improved order processing - Updated related scripts and configurations to support new functionality
This commit is contained in:
33
2.数据下载与处理/tick数据转分钟数据脚本/tick_to_min.py
Normal file
33
2.数据下载与处理/tick数据转分钟数据脚本/tick_to_min.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import pandas as pd
|
||||
|
||||
# 读取上传的CSV文件
|
||||
file_path = 'C:/Users/zhouj/Desktop/a次主力连续_20190103.csv'
|
||||
df = pd.read_csv(file_path, encoding='gbk')
|
||||
|
||||
# 重命名列以便处理
|
||||
df.rename(columns={'时间': 'datetime', '最新': 'price', '成交量': 'volume'}, inplace=True)
|
||||
|
||||
# 确保datetime列是datetime类型
|
||||
df['datetime'] = pd.to_datetime(df['datetime'])
|
||||
|
||||
# 设置datetime列为索引
|
||||
df.set_index('datetime', inplace=True)
|
||||
|
||||
# 使用resample方法将数据重新采样为1分钟数据
|
||||
df_resampled = df.resample('1T').agg({
|
||||
'price': ['first', 'max', 'min', 'last'],
|
||||
'volume': 'sum'
|
||||
})
|
||||
|
||||
# 重命名列名以符合K线数据的标准命名
|
||||
df_resampled.columns = ['open', 'high', 'low', 'close', 'volume']
|
||||
|
||||
# 删除存在NA值的行(如果有的时间段没有交易数据)
|
||||
df_resampled.dropna(inplace=True)
|
||||
|
||||
# 将重新采样的数据写入新的CSV文件
|
||||
output_file = 'C:/Users/zhouj/Desktop/tic_data_1min.csv'
|
||||
df_resampled.to_csv(output_file)
|
||||
|
||||
print(f'1分钟历史数据已保存至{output_file}')
|
||||
|
||||
Reference in New Issue
Block a user