I have an XLSX file which I am using python to convert to CSV to allow me to manipulate using pandas, I would then like to export the data from the CSV file into a formatted text document.
The xlsx data is as follows
| Name | Number | Branch Manager |
|---|---|---|
| Gustavo Barrett | 45 | Avery Page |
| Sterling Lynn | 199 | Matteo Hicks |
I would like the format to be as follows for the TXT file
*****NEW RECORD*****Name : Gustavo BarrettNumber : 45Branch Manager : Avery Page*****RECORD END**********NEW RECORD*****Name : Sterling LynnNumber : 199Branch Manager : Matteo Hicks*****RECORD END*****Below is my current code which prints all the names first, then the numbers and the branch managers, it prints them all separately, any idea how i can get it to output in the format i want?
import pandas as pdfrom pandas import DataFrameimport time with open("waffles.txt", "w") as file: filename = 'finals.xlsx' df = pd.DataFrame(pd.read_excel(filename)) names = df["Name"].to_list() numbers = df["Number"].to_list() branch = df["Branch Manager"].to_list() for i in names: for i in names: txt_name = "Name : "+str(i) for o in numbers: txt_number = "Number : "+str(o) for a in branch: txt_branch = "Branch Manager : "+str(a) file.write("\n") file.write("*****NEW RECORD*****") file.write("\n") file.write(i+"\n") file.write(str(o)+"\n") file.write(a+"\n") file.write("*****RECORD END*****") file.write("\n")