Python Forum

Full Version: Loading CSV trouble
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everyone,

I just started learning Python and having an issue with loading csv. I had it working yesterday. The goal is to load my CSV and eventually modify the data and save it as an excel file.

Visual Studio code is not showing an error, but it is not printing any of the CSV, here is the code. (Both my .py and .csv are in the same folder. Python Version 3.9.1, pandas and xlsxwriter installed w/ pip)

import pandas as pd
import xlsxwriter 
list = pd.read_csv('list.csv')
list.head()
you need to print it. probably, when you say it worked - it was in interactive python shell. but don't use list as name - it's a built-in function

import pandas as pd
df = pd.read_csv('list.csv') # df as DataFrame
print(df.head())
df.to_excel('list.xlsx')
No need to import xlsxwriter unless you plan to use it directly.
Thanks Buran, that worked