Name a dataframe based on csv file name?
问题 Trying to batch analyze a folder full of .csv files, then save them out again based on the .csv name. However, I'm having trouble extracting just the file name and assigning it to the dataframe (df). import glob import pandas as pd path = r'csv_in' allFiles = glob.glob(path + '/*.csv') for file_ in allFiles: df = pd.read_csv(file_, header=0) df.name = file_ print(df.name) The print result I get is "csv_in/*.csv". The result I'm looking for is just the csv name, "*.csv" 回答1: Create new column