gpt-3.5-turbo-1106· OpenAI
Arena Human Preference 55K
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 uses the
osmodule to read a folder and creates a DataFrame with the names of the PDF files using thepandaslibrary:import os import pandas as pd def list_pdf_files(folder_path): pdf_files = [f for f in os.listdir(folder_path) if f.endswith('.pdf')] return pdf_files def main(): folder_path = '/path/to/your/folder' pdf_files = list_pdf_files(folder_path) df = pd.DataFrame(pdf_files, columns=['File Name']) print(df) if __name__ == "__main__": main()Replace
'/path/to/your/folder'with the actual path of the folder you want to read. When you run the script, it will print a DataFrame with the names of the PDF files in the folder.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.