-3
import pandas as pd
df = pd.read_csv('E:/demographic-data.csv')

I'm try to read a csv file using pandas. But end up getting the below error. How can I solve this? enter image description here

  • 1
    double check the location of the file – stefan_aus_hannover Apr 22 '22 at 17:53
  • Welcome to Stack Overflow! Please take the [tour]. For debugging help in the future, first start with your own research, then if you need to post a question, you need to make a [mre] including the [full error message with traceback](https://meta.stackoverflow.com/q/359146/4518341) and working code. This code doesn't work because you imported `pandas` as `np`, not `pd`. You also need to include all the details, like whether the file actually exists. For more tips, including how to write a better title, see [ask]. – wjandrea Apr 22 '22 at 17:59
  • Oops, the question I linked is mostly about *relative* paths, not absolute paths. If it doesn't help, I'll gladly reopen your question, but please do add the other details I mentioned. – wjandrea Apr 22 '22 at 18:04

1 Answers1

-1

Try:

df = pd.read_csv('E://demographic-data.csv')
HackerMan
  • 53
  • 8
  • How would that help? Aren't double-forward slashes redundant? I know they are on Unix-like systems. Please [edit] to add an explanation. For tips, see [answer]. – wjandrea Apr 22 '22 at 18:01
  • I think he is using windows, I used to get this error on it and this would solve it. You can find its explanation here: https://stackoverflow.com/questions/15969608/what-is-the-difference-between-and-in-file-path – HackerMan Apr 22 '22 at 18:02
  • I don't ever need to double slash in file names on Windows with python. – stefan_aus_hannover Apr 22 '22 at 18:05
  • 1
    @HackerMan Even though this answer is not helpful it gets an upvote. How? – Sharim Iqbal Apr 22 '22 at 18:06
  • I tested the code bit on my windows machine as follows: ```df = pd.read_csv("E:\\demographic-data.csv")``` and I was able to load the data as a dataframe – Yayati Sule Apr 22 '22 at 18:07
  • I tried using this too, still getting the same error message. – HermioneCodes Apr 22 '22 at 18:08
  • @HackerMan That's talking about backslashes, not forward slashes. In Python, backslashes are escape characters, so [doubling them makes sense](/a/2953843/4518341), but forward slashes are not. – wjandrea Apr 22 '22 at 20:57
  • This does not work because forward slashes are not escaped. There is also no description that says how it actually solves the original proble. Recommending for deletion. – keiv.fly Apr 23 '22 at 14:54