Python Prompt for chatgpt
Python Prompt for chatgpt

Python code that extracts data from a CSV file

On sale for

Original price was: $1.10.Current price is: $0.00.

Prompt Details

This ChatGPT prompt is writing a Python code that can extract data from a CSV file and save it as a JSON file. CSV (Comma Separated Values) is a commonly used format for storing and exchanging data in a tabular form, while JSON (JavaScript Object Notation) is a lightweight data interchange format that is widely used in web applications.

Additional information

Engine

, ,

Prompt
				
					I want you to act as a programmer and write a Python code that extracts data from a CSV file and saves it as a JSON file.
				
			
Response

import csv
import json

# Open the CSV file
with open('input.csv', 'r') as csv_file:

# Parse the CSV file with a comma delimiter
csv_reader = csv.DictReader(csv_file, delimiter=',')

# Create an empty list to hold the data
data = []

# Loop through each row in the CSV file
for row in csv_reader:

# Append the row to the list
data.append(row)

# Open a new JSON file
with open(‘output.json’, ‘w’) as json_file:

# Write the data to the JSON file
json.dump(data, json_file)

Prompt
Response
Prompt
Response
Prompt
Response
Python Prompt for chatgpt
Python Prompt for chatgpt
Share this
Sample Input
Sample Output

Create

Please use this prompt responsibly

Share

Share your creations with your community

Learn

All the prompts are for educational purposes

Search...