I'm trying to add a variable from a list into a dataframe that is being passed through an appended list: The goal is to be able to identify the quotes with their respective symbol pairs:
symbol = ['EURUSD','USDJPY','USDCHF','USDCAD']
timeframe = mt.TIMEFRAME_M1
date_from = datetime(2023,10,27,16,55)
date_to = datetime.now()
price = []
for i in symbol:
data = mt.copy_rates_range(i,timeframe,date_from,date_to)
price.append(data['close'])
prices = pd.DataFrame(price)
prices
THE CURRENT RESULTS ARE:
0 1 2 3
0 1.05644 1.05654 1.05644 1.05640
1 149.63200 149.60200 149.58400 149.60400
2 0.90209 0.90217 0.90219 0.90238
3 1.38740 1.38726 1.38732 1.38729
THE DESIRED RESULTS ARE:
PAIR 0 1 2 3
0 EURUSD 1.05644 1.05654 1.05644 1.05640
1 USDJPY 149.63200 149.60200 149.58400 149.60400
2 USDCHF 0.90209 0.90217 0.90219 0.90238
3 USDCAD 1.38740 1.38726 1.38732 1.38729
I've tried concat and using "+" Tried this too: https://stackoverflow.com/questions/68010466/make-a-dataframe-column-with-names-of-variables-in-the-for-loop
Have you tried just to start each appending with
symbol
like this: