Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Data Science by (17.6k points)

I am completely new to python and programming in general.

I want to do the Famous "Titanic" Data Science Project but I am unable to read the CSV file although I uploaded them. I use Jupyter and Python 3.

I downloaded all CSV Files several times.

screenshot

# data analysis and wrangling

import pandas                as pd

import numpy                 as np

import random                as rnd

# visualization

import seaborn               as sns

import matplotlib.pyplot     as plt

%matplotlib inline

# machine learning

from sklearn.linear_model  import LogisticRegression

from sklearn.svm           import SVC, LinearSVC

from sklearn.ensemble      import RandomForestClassifier

from sklearn.neighbors     import KNeighborsClassifier

from sklearn.naive_bayes   import GaussianNB

from sklearn.linear_model  import Perceptron

from sklearn.linear_model  import SGDClassifier

from sklearn.tree          import DecisionTreeClassifier

##Acquire data

train_df   = pd.read_csv('../input/train.csv')    #here I get the error

test_df    = pd.read_csv('../input/test.csv')

combine    = [train_df, test_df]

Error: FileNotFoundError

Should I change the Directory Path? But if so in what way ?

1 Answer

0 votes
by (41.4k points)

Here, to load your dataframes, provide the full path of the csv file in both files 

train_df   = pd.read_csv('<path_to_csv>/train.csv')  

test_df    = pd.read_csv('<path_to_csv>/test.csv')

combine    = [train_df, test_df]

Or create the full path using os.path.join if you know the directory of the csv file.

import os

folder = "<path_to_csv>"

#Full path of csv files

train_path = os.path.join(folder, 'train.csv')

test_path = os.path.join(folder, 'test.csv')

#Use full path to open csv file

train_df = pd.read_csv(train_path)  

test_df = pd.read_csv(test_path)

combine = [train_df, test_df]

If you wish to know more about Python then visit this Python Course.

Related questions

0 votes
2 answers
asked Sep 17, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
asked Sep 6, 2019 in SQL by Sammy (47.6k points)

Browse Categories

...