my code : import pandas as pd import os validextrasdirectory = r"H:\trade\crypto…
- User
my code : import pandas as pd import os
valid_extras_directory = r"H:\trade\crypto data\day\to merge corrected"
def merge_valid_files(file_path): global df_merged first = True df_crypto = pd.read_csv(file_path)
df_crypto['Date'] = pd.to_datetime(df_crypto['Date']) for valid_extra in os.listdir(valid_extras_directory): if valid_extra.endswith(".csv"): valid_extra_path = os.path.join(directory, filename) extra_data = pd.read_csv(valid_extra_path) extra_data['Date'] = pd.to_datetime(extra_data['Date']) if first: df_merged = df_crypto.merge(extra_data, how='left', on='Date') first = False df_merged = df_merged.merge(extra_data, how='left', on='Date') return df_mergedYour directory containing CSV files
directory = r"C:\Users\Fazel\Downloads\crypto data\day\proc01" directory_out = r"C:\Users\Fazel\Downloads\crypto data\day\proc03_valid1_added"
Iterate over CSV files in the directory
for filename in os.listdir(directory): if filename.endswith(".csv"): file_path = os.path.join(directory, filename)
try: processed_df = merge_valid_files(file_path) name = filename[filename.find("Binance_"): filename.find("_d") + 2] # Optionally save the processed data frame to a new CSV file output_path = os.path.join(directory_out, f"valid_added_{name}") processed_df.to_csv(output_path, index=False) print(f"Processed and saved: {output_path}") except Exception as e: print(f"------------------>>>>>>>>>>>>>>>>>>>>>>>> An error occurred while processing {filename}: {e}")error : An error occurred while processing A_processed_A2_sorted_Binance_BRDBTC_d.csv: Passing 'suffixes' which cause duplicate columns {'trend_vortex_ind_diff_x', 'trend_psar_down_indicator_x', 'momentum_ppo_hist_x', 'volatility_bbli_x', 'volume_nvi_x', 'trend_vortex_ind_neg_x', 'momentum_ao_x', 'volatility_kcli_x', 'trend_ema_fast_x', 'volatility_bbp_x', 'tradecount_x', 'High_x', 'volatility_atr_x', 'trend_ichimoku_b_x', 'volatility_bbl_x', 'trend_aroon_up_x', 'trend_kst_sig_x', 'momentum_uo_x', 'momentum_tsi_x', 'Open_x', 'trend_aroon_ind_x', 'volatility_dcw_x', 'trend_stc_x', 'momentum_kama_x', 'volatility_kcp_x', 'trend_vortex_ind_pos_x', 'trend_ichimoku_conv_x', 'trend_macd_diff_x', 'trend_ema_slow_x', 'trend_adx_neg_x', 'trend_ichimoku_base_x', 'momentum_wr_x', 'volatility_bbhi_x', 'volume_vwap_x', 'volatility_kcw_x', 'trend_adx_x', 'volume_adi_x', 'momentum_rsi_x', 'Symbol_x', 'trend_kst_diff_x', 'trend_trix_x', 'trend_kst_x', 'momentum_stoch_signal_x', 'Unix_x', 'trend_macd_x', 'others_dr_x', 'Low_x', 'momentum_roc_x', 'volume_obv_x', 'momentum_stoch_rsi_k_x', 'volatility_bbw_x', 'trend_psar_down_x', 'volatility_kcc_x', 'volatility_dcl_x', 'trend_psar_up_indicator_x', 'momentum_stoch_rsi_x', 'momentum_stoch_rsi_d_x', 'momentum_pvo_x', 'volatility_kchi_x', 'momentum_stoch_x', 'volatility_bbm_x', 'volatility_bbh_x', 'trend_visual_ichimoku_a_x', 'trend_mass_index_x', 'volume_cmf_x', 'momentum_pvo_signal_x', 'trend_sma_fast_x', 'volume_em_x', 'trend_dpo_x', 'trend_adx_pos_x', 'volatility_kcl_x', 'volatility_dcm_x', 'volatility_dcp_x', 'trend_psar_up_x', 'volume_mfi_x', 'others_cr_x', 'volume_fi_x', 'momentum_pvo_hist_x', 'others_dlr_x', 'trend_sma_slow_x', 'volume_sma_em_x', 'volatility_ui_x', 'trend_ichimoku_a_x', 'volatility_kch_x', 'volume_vpt_x', 'momentum_ppo_signal_x', 'trend_macd_signal_x', 'volatility_dch_x', 'trend_visual_ichimoku_b_x', 'momentum_ppo_x', 'trend_aroon_down_x', 'Volume_x', 'Volume BTC_x', 'trend_cci_x', 'Close_x'} is not allowed. An error occurred while processing A_processed_A2_sorted_Binance_BRDETH_d.csv: Passing 'suffixes' which cause duplicate columns {'trend_vortex_ind_diff_x', 'trend_psar_down_indicator_x', 'momentum_ppo_hist_x', 'volatility_bbli_x', 'volume_nvi_x', 'trend_vortex_ind_neg_x', 'momentum_ao_x', 'volatility_kcli_x', 'trend_ema_fast_x', 'volatility_bbp_x', 'tradecount_x', 'High_x', 'volatility_atr_x', 'trend_ichimoku_b_x', 'volatility_bbl_x', 'trend_aroon_up_x', 'trend_kst_sig_x', 'momentum_uo_x', 'momentum_tsi_x', 'Open_x', 'trend_aroon_ind_x', 'volatility_dcw_x', 'trend_stc_x', 'momentum_kama_x', 'volatility_kcp_x', 'trend_vortex_ind_pos_x', 'trend_ichimoku_conv_x', 'trend_macd_diff_x', 'trend_ema_slow_x', 'trend_adx_neg_x', 'trend_ichimoku_base_x', 'momentum_wr_x', 'volatility_bbhi_x', 'volume_vwap_x', 'volatility_kcw_x', 'trend_adx_x', 'volume_adi_x', 'momentum_rsi_x', 'Symbol_x', 'trend_kst_diff_x', 'trend_trix_x', 'trend_kst_x', 'momentum_stoch_signal_x', 'Volume ETH_x', 'Unix_x', 'trend_macd_x', 'others_dr_x', 'Low_x', 'momentum_roc_x', 'volume_obv_x', 'momentum_stoch_rsi_k_x', 'volatility_bbw_x', 'trend_psar_down_x', 'volatility_kcc_x', 'volatility_dcl_x', 'trend_psar_up_indicator_x', 'momentum_stoch_rsi_x', 'momentum_stoch_rsi_d_x', 'momentum_pvo_x', 'volatility_kchi_x', 'momentum_stoch_x', 'volatility_bbm_x', 'volatility_bbh_x', 'trend_visual_ichimoku_a_x', 'trend_mass_index_x', 'volume_cmf_x', 'momentum_pvo_signal_x', 'trend_sma_fast_x', 'volume_em_x', 'trend_dpo_x', 'trend_adx_pos_x', 'volatility_kcl_x', 'volatility_dcm_x', 'volatility_dcp_x', 'trend_psar_up_x', 'volume_mfi_x', 'others_cr_x', 'volume_fi_x', 'momentum_pvo_hist_x', 'others_dlr_x', 'trend_sma_slow_x', 'volume_sma_em_x', 'volatility_ui_x', 'trend_ichimoku_a_x', 'volatility_kch_x', 'volume_vpt_x', 'momentum_ppo_signal_x', 'trend_macd_signal_x', 'volatility_dch_x', 'trend_visual_ichimoku_b_x', 'momentum_ppo_x', 'trend_aroon_down_x', 'Volume_x', 'trend_cci_x', 'Close_x'} is not allowed.
- Assistant