I need assistance modifying the font and size of excel spreadsheet from default to 'Arial' 9. I'm able to modify the header row, but unable to get the body of the spreadsheet to do the same. I'm using xlsxwriter, I'm sure it's something simple just not that familiar with xlsxwriter. See code below, any assistance greatly appreciated.
Pipeline_details.to_excel(writer1,
sheet_name ='Pipeline_Details',
startrow=1,
startcol=0,
header=False,
index=False)
workbook = writer1.book
worksheet = writer1.sheets['Pipeline Details']
(max_row, max_col) = Pipeline_details.shape
worksheet.autofilter(0,0,max_row, max_col - 1)
worksheer.hide_gridlines(2)
header_format = workbook_add.format({
'font_name': 'Arial',
'font_size': 9,
'bold': False,
'text_wrap': True})
for col_num, value in enumerate(Pipeline_details.columns.values):
worksheet.write(0, col_num, value, header_format)
cell_format = workbook.add_format({'font_name': 'Arial', 'font_size': 9})
writer1.save()
The docs for formatting while using pandas with xlsxwriter state the following:
XlsxWriter and Pandas provide very little support for formatting the output data from a dataframe apart from default formatting such as the header and index cells and any cells that contain dates or datetimes. In addition it isn’t possible to format any cells that already have a default format applied.
If you require very controlled formatting of the dataframe output then you would probably be better off using Xlsxwriter directly with raw data taken from Pandas.
That being said
It is possible to format any other, non date/datetime column data using set_column()
For an example using A notation, you'd execute this after writing your data to the worksheet:
worksheet.set_column('A:Z', None, format)
I'd try that first to see if you get anywhere with it. Otherwise I'd suggest writing your rows yourself and adding your format that way.
enter image description here
I have succesfully pulled the required data to a .xlsx worksheet. But when I am going to convert the data to pandas dataframe an error pops out. How to solve the issue?
You could try without using 'b' while opening that file
output = open('test.xlsx','w')
I am trying to read excel files using python and writing each sheet's data into separate csv file.
I am able to write the whole data but its just I am unable to get the header values.
Is there any way this can be resolved.
Here is the piece of code I am writing.
xyz.to_csv(f, index=False, header=None)
I use the following code to print a dataframe into a csv file based on the answers seen at this question:
How to avoid Python/Pandas creating an index in a saved csv?
y_insincere = [classify_text(text,trimmed_posterior_dict)<0 for text in X_test]
X_output = pd.DataFrame()
X_output['number'] = number
X_output['CASE'] = case
X_output.to_csv('submission.csv',header=True,columns = ['id','case'],index='False')
However, when I look at the csv file it has an extra column without a header with row indices. I tried other fixes from the above question, but nothing worked. I am stuck. Any help appreciated
While i am saving Data Frames in Excel format ("*.xlsx"), i would like to add time stamp to Excel file name.
How can i add run time time stamp to Data Frame while saving in Excel format while saving file using Pandas? Thank you
You can use datetime module. It's one of the python standard library, you can access it by pd.datetime like below.
import pandas as pd
writer = pd.ExcelWriter('output_{}.xlsx'.format(pd.datetime.today().strftime('%y%m%d-%H%M%S')))
df1.to_excel(writer,'Sheet1')
df2.to_excel(writer,'Sheet2')
writer.save()
And you can check format code table for the detail.