change dataframe header with 2 rows - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: change dataframe header with 2 rows (/thread-30613.html) |
change dataframe header with 2 rows - tonycat - Oct-28-2020 Hello, I am new to programming, have some questions , thanks ! I download stock quote from yahoo and return two dataframes, by 2 methods data1 = yf.download('msft ibm v',start ='2020-10-5') data2 = yf.download('msft ibm v' , group_by ='ticker',start ='2020-10-5') both of them have two rows of header question 1 :how to change data1 to data2 structure or change data2 to data1 structure? question 2 :how to store the dataframe to csv or db , with 2 rows of header? #pip install yfinance import yfinance as yf data1 = yf.download('msft ibm v',start ='2020-10-5') data2 = yf.download('msft ibm v' , group_by ='ticker',start ='2020-10-5') data1.tail(5) data2.tail(5 RE: change dataframe header with 2 rows - Askic - Oct-28-2020 (Oct-28-2020, 10:22 AM)tonycat Wrote: Hello, I am new to programming, have some questions , thanks ! Hello, for start, you can try to write data frames converted to string into text files and examine how columns are organized. Why writing to db? What do you want to actually do with these files? Start with this code: import yfinance as yf data1 = yf.download('msft ibm v', start='2020-10-5') data2 = yf.download('msft ibm v', group_by='ticker', start='2020-10-5') data1.tail(5) data2.tail(5) with open('Data1.txt', 'w') as data1_f: data1_f.write(data1.to_string()) with open('Data2.txt', 'w') as data2_f: data2_f.write(data2.to_string()) RE: change dataframe header with 2 rows - tonycat - Oct-29-2020 (Oct-28-2020, 05:32 PM)Askic Wrote:(Oct-28-2020, 10:22 AM)tonycat Wrote: Hello, I am new to programming, have some questions , thanks ! thanks |