I'm trying to input CSV information into a table in Excel but I don't know how, it would also help if I could create the table in a python script as well as reading in the CSV file in the same script. Please help.
Asked
Active
Viewed 494 times
0
-
Look into http://www.python-excel.org/ and the python module [csv](https://docs.python.org/2/library/csv.html). – wenzul Aug 14 '15 at 10:59
-
Why do you not import the csv-file into excel with standard excel import features? – wenzul Aug 14 '15 at 11:01
2 Answers
0
pandas
can be very helpful:
import pandas as pd
df = pd.read_csv(csv_file_path)
df.to_excel(excel_file_path)
This is using some default parameters, you might need to provide some info to read_csv and to_excel depending on how your csv file looks and what output you are expecting.

DeepSpace
- 78,697
- 11
- 109
- 154
-
-
@Shaneyg8 CSVs offer very limited flexibility in terms of formatting. The raw data is just separated by commas. – khajvah Aug 14 '15 at 11:00
-
@Shaneyg8 Formatting is best done with an excel module for Python. That or you could do it using Excel features itself. You want to make the Excel file first. – rassa45 Aug 14 '15 at 11:16
0
I have used openpyxl before and I find it to be extremely useful for this purpose. We can help you out more if you tell us exactly what you need. (Install it with pip
or download from the Internet)
Example code:
import csv
import openpyxl
wb = openpyxl.Workbook(write_only = True)
ws = wb.create_sheet()
with open("myfile.csv", "r") as f:
for line in f:
ws.append(line)
wb.save("file.xlsx")