(Mar-23-2020, 11:15 PM)BrandonKastning Wrote: Are the above >>> (<--- Is that a Python console command line) and then you typed "record['date_filed'] and it outputs "'1754-09-01' ?
>>>
is the interactive active shell that come with all Python version,i use a better one ptpython.This is very basic knowledge about Python,that you may struggle with
Running as file
.py
it would look like this,then need to use print()
.import requests from pprint import pprint url = 'https://raw.githubusercontent.com/brianwc/bulk_scotus/master/1700s/1754/84581.json' response = requests.get(url) record = response.json() #pprint(record) print(record['date_filed']) print(record['citation']['federal_cite_one'])
Output:1754-09-01
1 U.S. 1
(Mar-23-2020, 11:15 PM)BrandonKastning Wrote: Does pandas have df.to_csv() and df.to_mysql() ?Both to_csv and to_sql
(Mar-23-2020, 11:15 PM)BrandonKastning Wrote: Is Pandas a must? Or moving the data from one format to another sufficient without using Pandas. I notice you say it's useful for those who would require more .No,it can make data manipulation easier depend on the task that shall do with the data.
Are there ways of using dataframes in python without using Pandas; or is that recommended for something like this?
Can just use the dictionary and eg write those chosen values to a database.
There are also easier DB like TinyDB or dataset.
Demo dataset which has a lot power as build on top of SQLAlchemy.
import requests from pprint import pprint import dataset url = 'https://raw.githubusercontent.com/brianwc/bulk_scotus/master/1700s/1754/84581.json' response = requests.get(url) record = response.json() #pprint(record) print(record['date_filed']) print(record['citation']['federal_cite_one']) #--- DB db = dataset.connect('sqlite:///court.db') table = db['court_table'] table.insert(dict(record=record['date_filed'], case=100)) table.insert(dict(record=record['citation']['federal_cite_one'], case=25)Test.
λ ptpython -i court.py >>> table.find_one(case=25) OrderedDict([('id', 2), ('record', '1 U.S. 1'), ('case', 25)]) # can also to do SQL queries >>> result = db.query('SELECT * FROM court_table;') >>> for row in result: ... print(row) OrderedDict([('id', 1), ('record', '1754-09-01'), ('case', 100)]) OrderedDict([('id', 2), ('record', '1 U.S. 1'), ('case', 25)])