dellaklo
dellaklo

Reputation: 43

Read multiple csv files in a folder

I have multiple .csv files that represents a serious of measurements maiden.

I need to plot them in order to compare proceeding alterations.

I basically want to create a function with it I can read the file into a list and replay several of the "data cleaning in each .csv file" Then plot them all together in a happy graph

this is a task I need to do to analyze some results. I intend to make this in python/pandas as I might need to integrate into a bigger picture in the future but for now, this is it.

I basically want to create a function with it I can read the file into a big picture comparing it Graph.

I also have one file that represents background noise. I want to remove these values from the others .csv as well

import matplotlib.pyplot as plt
from matplotlib.ticker import FormatStrFormatter
PATH = r'C:\Users\UserName\Documents\FSC\Folder_name'
FileNames = [os.listdir(PATH)]
for files in FileNames:
    df = pd.read_csv(PATH + file, index_col = 0)

I expected to read every file and store into this List but I got this code:

FileNotFoundError: [Errno 2] File b'C:\Users\UserName\Documents\FSC\FolderNameFileName.csv' does not exist: b'C:\Users\UserName\Documents\FSC\FolderNameFileName.csv'

Upvotes: 2

Views: 3566

Answers (1)

Umar.H
Umar.H

Reputation: 23099

Have you used pathlib from the standard library? it makes working with the file system a breeze,

recommend reading : https://realpython.com/python-pathlib/

try:

from pathlib import Path
files = Path('/your/path/here/').glob('*.csv') # get all csvs in your dir.
for file in files:
   df = pd.read_csv(file,index_col = 0)
   # your plots.

Upvotes: 10

Related Questions