Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Loading CSV trouble
#1
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()
buran write Jan-12-2021, 08:29 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply
#2
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.
DrinkinBeer likes this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Thanks Buran, that worked
Reply


Forum Jump:

User Panel Messages

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