Apr-19-2020, 05:18 AM
(This post was last modified: Apr-19-2020, 05:21 AM by BrandonKastning.)
snippsat,
Like you said this is very basic Python that is difficult for me as a newbie. I agree. Could I ask a few things to help me understand how to use what's being brought into python a little better until I fully understand how to read and modify the existing code?
for instance;
print(record['date_filed'])
print(record['citation']['federal_cite_one'])
How would you assign the value of 'date_filed' to
pythonvariable_date_filed = print(record['date_filed']) # DEFINED #
pythonvariable_citation = print(record['citation']['federal_cite_one']) # DEFINED #
I don't think I am understanding correctly.
Basically how to take the dictionary that was once the .json file and turn it into a dictionary like the python program does using import requests.
How to assign a python variable to each record in the dictionary?
I want to learn this prior to passing it over to dataset to make it easier for me to understand.
Like you said this is very basic Python that is difficult for me as a newbie. I agree. Could I ask a few things to help me understand how to use what's being brought into python a little better until I fully understand how to read and modify the existing code?
for instance;
print(record['date_filed'])
print(record['citation']['federal_cite_one'])
How would you assign the value of 'date_filed' to
pythonvariable_date_filed = print(record['date_filed']) # DEFINED #
pythonvariable_citation = print(record['citation']['federal_cite_one']) # DEFINED #
I don't think I am understanding correctly.
(Mar-24-2020, 01:03 AM)snippsat Wrote:(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 useprint()
.
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)])
Basically how to take the dictionary that was once the .json file and turn it into a dictionary like the python program does using import requests.
How to assign a python variable to each record in the dictionary?
I want to learn this prior to passing it over to dataset to make it easier for me to understand.
“And one of the elders saith unto me, Weep not: behold, the Lion of the tribe of Juda, the Root of David, hath prevailed to open the book,...” - Revelation 5:5 (KJV)
“And oppress not the widow, nor the fatherless, the stranger, nor the poor; and ...” - Zechariah 7:10 (KJV)
#LetHISPeopleGo
“And oppress not the widow, nor the fatherless, the stranger, nor the poor; and ...” - Zechariah 7:10 (KJV)
#LetHISPeopleGo