close

How to open my files in data_folder with pandas using relative path?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to open my files in data_folder with pandas using relative path in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to open my files in data_folder with pandas using relative path?

  1. How to open my files in data_folder with pandas using relative path?

    Pandas will start looking from where your current python file is located. Therefore you can move from your current directory to where your data is located with '..'

  2. open my files in data_folder with pandas using relative path

    Pandas will start looking from where your current python file is located. Therefore you can move from your current directory to where your data is located with '..'

Method 1

Try

import pandas as pd
pd.read_csv("../data_folder/data.csv")

Method 2

Pandas will start looking from where your current python file is located. Therefore you can move from your current directory to where your data is located with ‘..’ For example:

pd.read_csv('../../../data_folder/data.csv')

Will go 3 levels up and then into a data_folder (assuming it’s there) Or

pd.read_csv('data_folder/data.csv')

assuming your data_folder is in the same directory as your .py file.

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read