from concurrent.futures import ThreadPoolExecutor, ascompleted sls = [0.07] tls = [0.1]…
- User
from concurrent.futures import ThreadPoolExecutor, as_completed sls = [0.07] tls = [0.1] hours_to_look = [2 ] symbols = pred_df['Symbol'].unique() current_symbol = '' columns = [] for sl in sls: for tl in tls: for hours in hours_to_look: columns.append(f'{sl}{tl}{hours}') combined_columns = list(pred_df.columns) + columns all_results= [] with ThreadPoolExecutor() as executor: futures = [] for index, row in pred_df.iterrows(): date, symbol, start_price = row['Date'], row['Symbol'], row['Close'] row_result = [] if(symbol != current_symbol): hourly_path = find_first_matching_1h(symbol) hourly_df = pd.read_csv(hourly_path) hourly_df['Date'] = pd.to_datetime(hourly_df['Date'], format="ISO8601", utc=True)
codefor sl in sls: for tl in tls: for hours in hours_to_look: futures.append(executor.submit(analyze_price_move,date, start_price,sl,tl,hourly_df, hours)) row_result.append(result) all_results.append(row_result) print(f'cell_done {len(all_results)}') for future in as_completed(futures): passfor i, new_cols in enumerate(columns): # This loop assumes all_results is correctly populated and matches the shape pred_df[new_cols] = [row[i] for row in all_results]
in this code the result wich added to the list(by row_result.append(result)) are all empty
fix it
- Assistant
- User
whith this approach the items not added by desired order to the list because when result being append in the try: result = future.result() row_result.append(result) it will not added by the order
- Assistant
- User
{ "name": "ValueError", "message": "Length of values (10) does not match length of index (5)", "stack": "--------------------------------------------------------------------------- ValueError Traceback (most recent call last) Cell In[23], line 46 42 print(f'cell_done {len(all_results)}') 45 for i, new_cols in enumerate(columns): # This loop assumes all_results is correctly populated and matches the shape ---> 46 pred_df[new_cols] = [row[i] for row in all_results]
- Assistant