-1

I've tried to search online, but with no sucesess. I have an output code which I try to export as csv file after modulations. When I open the exported file the width and height are just too small it looks like that the export code I have thus far is:

date = str(pd.to_datetime('today')).split()[0]
output.to_csv(f"{date} shifts.csv", index_label=False, index=False)

I want to make it more spaced by a fixed value I will provide. How can I do that? Thanks alot!

2
  • CSV != spreadsheet file. Commented Aug 12, 2023 at 15:20
  • 1
    CSV files do not have a width or height. Presumably you are loading a CSV file into a spreadsheet like Excel. Which means this has nothing to do with Python and you should ask for help in the appropriate support forum(s) for the spreadsheet app you are using. Commented Aug 12, 2023 at 19:13

1 Answer 1

0

The CSV file is a pure text file, where the values a seperated by commata. Therefore there is no width in a CSV. I assume, you are using Excel to open the CSV file, and Excel does apply a standard column width, and that is what you see.

You might want to save directly into Excel format instead of CSV. Then you can also change the width of the columns. Here is an example:

import pandas as pd

df = pd.DataFrame({'Data': [10, 20, 30, 20, 15, 30, 45]})
writer = pd.ExcelWriter('pandas_simple.xlsx', engine='xlsxwriter')
df.to_excel(writer, sheet_name='Sheet1')

# Set column width
worksheet = writer.sheets['Sheet1']
worksheet.set_column('A:A', 50)

writer.save()

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.