0
Problems with Reading a csv file
Hi i hope there is someone who can help me figure out what it is i am doing wrong when i try to read and view the data from a csv file i get the following error File "file0.py", line 2 def open_csv_file (".. \ Playground \\ Python \ Pythontest \ CSV files \ numbers.csv"): ^ SyntaxError: invalid syntax
5 Respuestas
+ 2
do not use a simple \ in the path, use two of them:
"..\\Playground\\Python..."
also, make sure to removes spaces in the path as it will not find the file.
I noticed you are placing a string as a parameter definition, that will not work, do this instead:
def open_csv_file(path):
# code to open the file here
open_csv_file("..\\path\\to\\file.csv")
-------------
side note: don't put url in the tags, it's unclickable there. you could use "python" and "syntax error" in there, it'd be more relevent.
0
Hi Apollo
thanks for your input but I'm afraid I do not understand it correctly as the code still does not work for me
thanks for your side note, I will remember that for next time
0
Are you getting new errors? What does your code looks like now?
0
I have changed my code to the following.
import pandas as pd
def open_csv_file ("\\ Users \\ krumh \\ Documents \\ BKLalt \\ Python \\ Pythontest \\ CSVfiler \\ numbers.csv"):
open_csv_file ("\\ Users \\ krumh \\ Documents \\ BKLalt \\ Python \\ Pythontest \\ CSVfiler \\ numbers.csv")
0
I'd recommend you to have another look at the function lessons.
You cannot delare a string in the parameters of a function. look at my example more carefully in my previous answer.
Also, you have changed the path to use double \\ but you left the spaces, which makes it an invalid path.
"\\ Users \\ krumh \\ Documents \\ BKLalt \\ Python \\ Pythontest \\ CSVfiler \\ numbers.csv"
vs
"\\Users\\krumh\\Documents\\BKLalt\\Python\\Pythontest\\CSVfiler\\numbers.csv"