Getting stock data in a discipline manner from Yahoo finance
I used the below code for downloading stock data from yahoo finance:-
import yfinance as yf
import datetime
stocks = ["AXISBANK.NS", "HDFCBANK.NS", "ICICIBANK.NS" ,"INDUSINDBK.NS",
"KOTAKBANK.NS",
"SBIN.NS",
"YESBANK.NS"]
start = datetime.datetime(2018,1,1)
end = datetime.datetime(2019,7,17)
data = yf.download(stocks, start=start, end=end)
data
I get the data in a below manner:-
I saved the data using panda:-
import pandas as pd
df = pd.DataFrame(data)
# saving the dataframe
df.to_csv('BANKING STOCK.csv')
I got the data in this format:-
But I ant my data in this format:-
Because this format is more convenient for analyzing data through SQL. How can I change the format of the data?
Topic csv data-formats pandas python
Category Data Science