I have multiple .cnv files that I can import and concatenate with the following code:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import glob
# Get CSV files list from a folder
path ='/Users/mariacristinaalvarez/Documents/High3/'
csv_files = glob.glob(path + "/*_high3.cnv")
# Read each CSV file into DataFrame
# This creates a list of dataframes
df_list = (pd.read_csv(file, encoding="ISO-8859-1",delim_whitespace=True,skiprows=316 , header=None) for file in csv_files1)
# Concatenate all DataFrames
stations_df = pd.concat(df_list)
This code works for me to get all files concatenated into one, but I would like to have a column with the filename that is contained between '' . For example: filename = 'HLY2202_008_high3_predown_av1dbar.cnv' I would like to only extract the numbers after HLY2202 AND before _high3 So the return should be "008" I want to do this for each file and add the name as a column so it becomes a identifier when I do explorative data analysis.