如何在 pandas 中已存在的数据集中添加更多数据集数据?
How can i add more dataset data in already exist dataset in pandas?
我有一个输出 csv 格式 excel 文件,我想使用 pandas 在其中添加更多数据。
我创建了一个输出文件,但我想在该输出文件中添加更多数据,我该怎么做?
这是我创建输出文件的代码,我不想更改此代码中的任何内容-
output_df = pd.DataFrame(columns=['Symbol', 'Date', 'Entry_time', 'Exit_time', 'Multiplier',
'Round-Off', 'Stop_loss %', 'Minimum_Expiry', 'GapUp/GapDown',
'Entry_price_ce', 'Stop_loss_ce', 'Stop_loss_price_ce', 'Exit_time_ce', 'Exit_price_ce',
'Entry_price_pe', 'Stop_loss_pe', 'Stop_loss_price_pe', 'Exit_price_pe', 'Exit_time_pe',
'PNL_ce', 'PNL_pe'])
c = 0
output_df.loc[c]=[symbol, date, entry_time, exit_time, multiplier, roundoff, stop_loss_pr,
min_expiry, gap, entry_price_ce, stop_loss_ce, stop_loss_price_ce, exit_time_ce,
exit_price_ce, entry_price_pe, stop_loss_pe, stop_loss_price_pe, exit_price_pe, exit_time_pe,
pnl_ce, pnl_pe]
mergefile.append(output_df)
DT_Sell = pd.concat(mergefile)
df = DT_Sell.drop_duplicates(subset='Date', keep="first")
df.reset_index(drop=True, inplace=True)
display(df)
csv_path = Path(r'C:\Users\krishna gupta\Global_trader\My Codes\DT\CSV\DT_Buy')
starting_time = entry_time.strftime("%H-%M-%S")
end_time = exit_time.strftime("%H-%M-%S")
df.to_csv(csv_path / f'DT_Buy_{starting_time}_{end_time}_{stop_loss_pr}_{multiplier}_{roundoff}.csv', index=False)
有什么方法可以将我的代码的新输出附加到我的旧 csv 输出文件中?我用相同的代码创建的。
要附加到 csv 文件,请使用 df.to_csv(filename, mode='a')
我有一个输出 csv 格式 excel 文件,我想使用 pandas 在其中添加更多数据。 我创建了一个输出文件,但我想在该输出文件中添加更多数据,我该怎么做?
这是我创建输出文件的代码,我不想更改此代码中的任何内容-
output_df = pd.DataFrame(columns=['Symbol', 'Date', 'Entry_time', 'Exit_time', 'Multiplier',
'Round-Off', 'Stop_loss %', 'Minimum_Expiry', 'GapUp/GapDown',
'Entry_price_ce', 'Stop_loss_ce', 'Stop_loss_price_ce', 'Exit_time_ce', 'Exit_price_ce',
'Entry_price_pe', 'Stop_loss_pe', 'Stop_loss_price_pe', 'Exit_price_pe', 'Exit_time_pe',
'PNL_ce', 'PNL_pe'])
c = 0
output_df.loc[c]=[symbol, date, entry_time, exit_time, multiplier, roundoff, stop_loss_pr,
min_expiry, gap, entry_price_ce, stop_loss_ce, stop_loss_price_ce, exit_time_ce,
exit_price_ce, entry_price_pe, stop_loss_pe, stop_loss_price_pe, exit_price_pe, exit_time_pe,
pnl_ce, pnl_pe]
mergefile.append(output_df)
DT_Sell = pd.concat(mergefile)
df = DT_Sell.drop_duplicates(subset='Date', keep="first")
df.reset_index(drop=True, inplace=True)
display(df)
csv_path = Path(r'C:\Users\krishna gupta\Global_trader\My Codes\DT\CSV\DT_Buy')
starting_time = entry_time.strftime("%H-%M-%S")
end_time = exit_time.strftime("%H-%M-%S")
df.to_csv(csv_path / f'DT_Buy_{starting_time}_{end_time}_{stop_loss_pr}_{multiplier}_{roundoff}.csv', index=False)
有什么方法可以将我的代码的新输出附加到我的旧 csv 输出文件中?我用相同的代码创建的。
要附加到 csv 文件,请使用 df.to_csv(filename, mode='a')