i'm new to Python. I want to insert specific columns of a csv file into a collection in my mongodb, i know how to do it with the shell but i want to do it with python, as i'm learning Python.
This is what i have so far:
import csv
import json
import pandas as pd
import sys, getopt, pprint
from pymongo import MongoClient
#CSV to JSON Conversion
with open('netflix_titles.csv','rt', encoding="utf8") as file:
data = file.read()
mongo_client=MongoClient()
db=mongo_client.Netflix
db.segment.drop()
header= [ "show_id", "director"]
for each in data:
row={}
for field in header:
row[field]=each[field]
db.segment.insert(row)
In only throws me an indented error in this line:
data = file.read()