Hi, is there any way in Python for me to change the columns' positions like below:
Thanks a lot!
Update: I have been trying to reframe the columns in the dump way, any code I can apply to increase the efficiency? Thanks.
now = dt.datetime.now()
length = relativedelta(weeks = 8)
start = now - length
end = now
stocks = ['TSLA','AMZN','FB']
tokens = ['BTC-USD','ETH-USD','DOGE-USD','XRP-USD']
#2. Get data and arrange them together without NaNs
stocks = web.DataReader(stocks, 'yahoo', start, end)
tokens = web.DataReader(tokens, 'yahoo', start, end)
df = tokens.merge(stocks, how='inner', right_index = True, left_index = True)
df.dropna(inplace = True)
df = df[[('Open', 'TSLA'),('High', 'TSLA'),('Low', 'TSLA'),('Close', 'TSLA'),('Adj Close', 'TSLA'),('Volume', 'TSLA'),
('Open', 'AMZN'),('High', 'AMZN'),('Low', 'AMZN'),('Close', 'AMZN'),('Adj Close', 'AMZN'),('Volume', 'AMZN'),
('Open', 'FB'),('High', 'FB'),('Low', 'FB'),('Close', 'FB'),('Adj Close', 'FB'),('Volume', 'FB'),
('Open', 'BTC-USD'),('High', 'BTC-USD'),('Low', 'BTC-USD'),('Close', 'BTC-USD'),('Adj Close', 'BTC-USD'),('Volume', 'BTC-USD'),
('Open', 'ETH-USD'),('High', 'ETH-USD'),('Low', 'ETH-USD'),('Close', 'ETH-USD'),('Adj Close', 'ETH-USD'),('Volume', 'ETH-USD'),
('Open', 'DOGE-USD'),('High', 'DOGE-USD'),('Low', 'DOGE-USD'),('Close', 'DOGE-USD'),('Adj Close', 'DOGE-USD'),('Volume', 'DOGE-USD'),
('Open', 'XRP-USD'),('High', 'XRP-USD'),('Low', 'XRP-USD'),('Close', 'XRP-USD'),('Adj Close', 'XRP-USD'),('Volume', 'XRP-USD')]]
df.to_csv('Data/newohlc.csv')