EXPORT DATAFRAME TO EXCEL, CSV & TEXT FILE IN PANDAS
import pandas as pd
st = pd.read_excel("C:\\Users\\mahes\\OneDrive\\Documents\\Students.xlsx")
sd = pd.DataFrame(st)
print(st)
Making some changes in the dataframe
st['Total']=st['Hindi']+st['English'] +st['Science'] +st['History']+st['Mathematics']
Now, exporting the DataFrame as Excel, CSV and Text File
sd.to_excel("C:\\Users\\mahes\\OneDrive\\Desktop\\StudentsNew.xlsx")
sd.to_csv("C:\\Users\\mahes\\OneDrive\\Desktop\\StudentsNew.csv")
sd.to_csv("C:\\Users\\mahes\\OneDrive\\Desktop\\StudentsNew.txt" ,sep = "\t")
As you can see we have created three new files.
0 Comments:
Post a Comment