0

I am importing a file with the extension csv and reading the rows to make a list.

import csv
with open("passwords.csv") as csvfile:
     reader = csv.reader(csvfile) 

     newList = []
     for row in reader:
         for i in row:
             nrwList.append(i)

With the IDE Spyder, I have opened passwords.csv in one of my tabs. When I run the program, it gives me an error saying no such file or directory.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245

1 Answers1

0

Two actions:

Provide the full path: home/user/....../passwords.csv or define the directory path in Spyder (preferences)

Then:

import pandas as pd
pd.read_csv("home/user/....../passwords.csv", sep=',',header=0)
razimbres
  • 4,715
  • 5
  • 23
  • 50
  • Let's say if I wanted to ask the user for the file through an input, how would the directory work? –  Apr 03 '21 at 15:25
  • dir=input("Specify the directory"). Then `pd.read_csv(dir, sep=',',header=0)` – razimbres Apr 03 '21 at 15:28