Python Forum
JSON -> CSV conversion help! *I think Nested JSON*
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
JSON -> CSV conversion help! *I think Nested JSON*
#4
(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 Wink
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 .
Are there ways of using dataframes in python without using Pandas; or is that recommended for something like this?
No,it can make data manipulation easier depend on the task that shall do with the data.
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)])
Reply


Messages In This Thread
RE: JSON -> CSV conversion help! *I think Nested JSON* - by snippsat - Mar-24-2020, 01:03 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to generating multiple json files using python script dzgn989 4 274 May-10-2024, 03:09 PM
Last Post: deanhystad
  encrypt data in json file help jacksfrustration 1 326 Mar-28-2024, 05:16 PM
Last Post: deanhystad
Exclamation Json API JayPy 4 518 Mar-04-2024, 04:28 PM
Last Post: deanhystad
  json loads throwing error mpsameer 8 820 Jan-23-2024, 07:04 AM
Last Post: deanhystad
  Parsing large JSON josvink66 5 757 Jan-10-2024, 05:46 PM
Last Post: snippsat
  parse json field from csv file lebossejames 4 828 Nov-14-2023, 11:34 PM
Last Post: snippsat
  format json outputs ! evilcode1 3 1,793 Oct-29-2023, 01:30 PM
Last Post: omemoe277
  JSON Dump and JSON Load foxholenoob 8 1,254 Oct-12-2023, 07:21 AM
Last Post: foxholenoob
  TypeRoor reading json GreenLynx 3 943 May-16-2023, 01:47 PM
Last Post: buran
  Python Script to convert Json to CSV file chvsnarayana 8 2,645 Apr-26-2023, 10:31 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020