Python Forum
help with exporting functions to excel
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help with exporting functions to excel
#2
If you are trying to export to new csv/excel file having head(), describe(), mean(),median(), mode() etc of given input file, you may try below and see if that helps.

import pandas as pd
 
data = pd.read_csv("inputbook.csv",encoding='latin-1')
data.columns = [c.replace(' ', '_') for c in data.columns] 
data.columns = [c.replace("'", '') for c in data.columns]

info_dict = data.head()
descdata=data.describe()
meandata=data.mean()
mediandata=data.median()
modedata=data.mode()

db=pd.DataFrame(columns=['------------empty line-----------------'])


open("output.csv", 'w')  #empty the csv file
descdata.to_csv("output.csv", mode='a', header=True)
db.to_csv('output.csv',mode='a',header=True)  #add empty line
info_dict.to_csv('output.csv', mode='a', header=True)
db.to_csv('output.csv',mode='a',header=True)  #add empty line
meandata.to_csv('output.csv',mode='a',header=True)
db.to_csv('output.csv',mode='a',header=True)  #add empty line
mediandata.to_csv('output.csv',mode='a',header=True)
db.to_csv('output.csv',mode='a',header=True)  #add empty line
modedata.to_csv('output.csv',mode='a',header=True)
Best Regards,
Sandeep

GANGA SANDEEP KUMAR
Reply


Messages In This Thread
help with exporting functions to excel - by avanage - Dec-15-2019, 05:25 AM
RE: help with exporting functions to excel - by sandeep_ganga - Dec-24-2019, 12:58 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Exporting data frame to excel dyerlee91 0 1,631 Oct-05-2021, 11:34 AM
Last Post: dyerlee91

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020