I´m learning python. I tried to get historical data of multiple stocks from MT5 however the stocks ' arrays have diferent lengths and I do not know how to solve it.
error: ValueError: Length of values (71) does not match length of index (100)
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
import pandas as pd
from time import sleep
from pathlib import Path
import os
import glob
import numpy as np
import matplotlib.pyplot as plt
import MetaTrader5 as mt5
from datetime import datetime
if not mt5.initialize():
print("initialize() failed, error code =", mt5.last_error())
quit()
s = Service(ChromeDriverManager().install())
wd = webdriver.Chrome(service=s)
wd.get("https://sistemaswebb3-listados.b3.com.br/indexPage/day/IBRA?language=pt-br")
sleep(3)
wd.find_element(By.ID,"segment").send_keys("Setor de Atuação")
sleep(3)
wd.find_element(By.PARTIAL_LINK_TEXT,"Download").click()
sleep(3)
list_of_files = glob.glob("C:/Users/xxxxx/Downloads/*") # * means all if need specific format then *.csv
latest_file = max(list_of_files, key=os.path.getctime)
lista= pd.read_csv(latest_file, sep=';', encoding='ISO-8859-1',skiprows = 0, skipfooter=2, engine='python', thousands='.',decimal=',', header=1, index_col=False)
ativos = pd.DataFrame(lista)
lista = ativos['Código']
df = pd.DataFrame()
for i in lista:
barras = mt5.copy_rates_from(i, mt5.TIMEFRAME_D1, datetime.today(), 100)
df[i] = barras['close']
print(df)