Create a py script that reads a folder and creates a df with the name of the files if…
- User
Create a py script that reads a folder and creates a df with the name of the files if they are a pdf
Assistant
Here's a Python script that reads a folder and creates a DataFrame with the names of PDF files:
pythonimport os import pandas as pd # Set the directory path dir_path = r'/path/to/folder' # Get all files in the directory files = os.listdir(dir_path) # Create an empty list to store the PDF file names pdf_files = [] # Iterate over all the files and check if they are PDFs for file in files: if file.endswith('.pdf'): pdf_files.append(file) # Create a DataFrame with the PDF file names df = pd.DataFrame(pdf_files, columns=['PDF Files']) # Export the DataFrame to CSV df.to_csv('pdf_files.csv')
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.