0

I am trying to open a file with the extension .csv in python, however it keeps saying that the file is not found. I am copying the path from the side bar, so I don't believe that's the problem

I have tried to insert / and ./ before the path of the file And r in front of the file name

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt 
from scipy.optimize import curve_fit

bkgrnd = pd.read_csv('/Desktop/Sro/Natrium22.csv')

No matter what I've tried, it keeps saying FileNotFoundError

Ashish Kamble
  • 2,555
  • 3
  • 21
  • 29
  • Possible duplicate of [pandas.read\_csv file not found despite correct path with raw text](https://stackoverflow.com/questions/42165649/pandas-read-csv-file-not-found-despite-correct-path-with-raw-text) – Ashish Kamble Apr 26 '19 at 10:30
  • You are putting `/` root to `/Desktop` please provide fully qualified filename – Ashish Kamble Apr 26 '19 at 11:40

1 Answers1

0

you can import csv if file will be always .csv,

import csv

with open('C:\Users\user\Desktop\Sro\Natrium22.csv') as csv_file:
    csv_reader = csv.reader(csv_file, delimiter=',')
    line_count = 0
    for row in csv_reader:

specifix on windows, it needs normalization of your pathname, maybe thats the issue, try doing, will surely work,

import os
import pandas as pd

cwd = os.getcwd()
filePath = 'C:/Users/user/Desktop/Sro/Natrium22.csv'
data = pd.read_csv(os.path.normcase(os.path.join(cwd, filePath)))
print(data)

you can try even,

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt 
from scipy.optimize import curve_fit

bkgrnd = pd.read_csv(r'C:\Users\user\Desktop\Sro\Natrium22.csv')
print(bkgrnd)
Ashish Kamble
  • 2,555
  • 3
  • 21
  • 29