2

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'

1
  • 3
    Try adding a \ to the end of your PATH value, e.g. 'C:\Users\UserName\Documents\FSC\Folder_name\' Commented Nov 7, 2019 at 16:06

1 Answer 1

10

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.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.