Created
June 29, 2020 17:22
-
-
Save ra312/38239c6b954f90ba53bba25c83518f72 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is an application transferring csv data into database | |
# We choose a NoSQL database MongoDB since we have to store data and the logs of data GET requests# We prefer to choose PostgreSQL rather than MySQL(purely relation) or SQLite (no concurrency support) | |
import json | |
import csv | |
import pandas as pd | |
import os | |
from pymongo import MongoClient | |
cwd = os.path.dirname(__file__) | |
csvpath=os.path.join(cwd,'task_data.csv') | |
csv_records = pd.read_csv(csvpath) | |
csv_records.to_json(path_or_buf='task_data.json',orient='split') | |
client = MongoClient('localhost', 27017) | |
db = client['task'] | |
collection_tasks = db['task_data'] | |
with open('task_data.json') as f: | |
file_data = json.load(f) | |
collection_tasks.insert_many(csv_records.to_dict()) | |
client.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment