I have a .csv file on my F: drive on Windows 7 64-bit that I'd like to read into pandas and manipulate.
None of the examples I see read from anything other than a simple file name (e.g. 'foo.csv').
When I try this I get error messages that aren't making the problem clear to me:
import pandas as pd
trainFile = "F:/Projects/Python/coursera/intro-to-data-science/kaggle/data/train.csv"
trainData = pd.read_csv(trainFile)
IOError: Initializing from file failed
if __name__ == '__main__':
trainPath = 'F:/Projects/Python/coursera/intro-to-data-science/kaggle/data/train.csv'
trainData = 
with open(trainPath, 'r') as trainCsv:
trainReader = csv.reader(trainCsv, delimiter=',', quotechar='"')
for row in trainReader:
I cannot promise that this will work, but it's worth a shot:
import pandas as pd import os trainFile = "F:/Projects/Python/coursera/intro-to-data-science/kaggle/data/train.csv" pwd = os.getcwd() os.chdir(os.path.dirname(trainFile)) trainData = pd.read_csv(os.path.basename(trainFile)) os.chdir(pwd)