0% found this document useful (0 votes)
32 views2 pages

Working With Json and SQL Files Cheatsheet

The document discusses working with JSON and SQL data in Python using the Pandas library. It shows how to load JSON and SQL data into Pandas DataFrames and perform basic operations like selecting columns and filtering rows.

Uploaded by

Yajur Agarwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views2 pages

Working With Json and SQL Files Cheatsheet

The document discusses working with JSON and SQL data in Python using the Pandas library. It shows how to load JSON and SQL data into Pandas DataFrames and perform basic operations like selecting columns and filtering rows.

Uploaded by

Yajur Agarwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

In 

[11]: import pandas as pd

Woking with JSON


In [12]: pd.read_json('train.json')

Out[12]: id cuisine ingredients

0 10259 greek [romaine lettuce, black olives, grape tomatoes...

1 25693 southern_us [plain flour, ground pepper, salt, tomatoes, g...

2 20130 filipino [eggs, pepper, salt, mayonaise, cooking oil, g...

3 22213 indian [water, vegetable oil, wheat, salt]

4 13162 indian [black pepper, shallots, cornflour, cayenne pe...

... ... ... ...

39769 29109 irish [light brown sugar, granulated sugar, butter, ...

39770 11462 italian [KRAFT Zesty Italian Dressing, purple onion, b...

39771 2238 irish [eggs, citrus fruit, raisins, sourdough starte...

39772 41882 chinese [boneless chicken skinless thigh, minced garli...

39773 2362 mexican [green chile, jalapeno chilies, onions, ground...

39774 rows × 3 columns

In [16]: pd.read_json('https://api.exchangerate-api.com/v4/latest/INR')

Out[16]: api_url api_docs api_terms base date time_last_updated rates

AED https://www.exchangerate-api.com https://www.exchangerate-api.com/docs/free https://www.exchangerate-api.com/terms INR 2021-03-31 1617148801 0.050110

AFN https://www.exchangerate-api.com https://www.exchangerate-api.com/docs/free https://www.exchangerate-api.com/terms INR 2021-03-31 1617148801 1.051777

ALL https://www.exchangerate-api.com https://www.exchangerate-api.com/docs/free https://www.exchangerate-api.com/terms INR 2021-03-31 1617148801 1.426475

AMD https://www.exchangerate-api.com https://www.exchangerate-api.com/docs/free https://www.exchangerate-api.com/terms INR 2021-03-31 1617148801 7.270000

ANG https://www.exchangerate-api.com https://www.exchangerate-api.com/docs/free https://www.exchangerate-api.com/terms INR 2021-03-31 1617148801 0.024424

... ... ... ... ... ... ... ...

XOF https://www.exchangerate-api.com https://www.exchangerate-api.com/docs/free https://www.exchangerate-api.com/terms INR 2021-03-31 1617148801 7.637893

XPF https://www.exchangerate-api.com https://www.exchangerate-api.com/docs/free https://www.exchangerate-api.com/terms INR 2021-03-31 1617148801 1.389489

YER https://www.exchangerate-api.com https://www.exchangerate-api.com/docs/free https://www.exchangerate-api.com/terms INR 2021-03-31 1617148801 3.411028

ZAR https://www.exchangerate-api.com https://www.exchangerate-api.com/docs/free https://www.exchangerate-api.com/terms INR 2021-03-31 1617148801 0.204121

ZMW https://www.exchangerate-api.com https://www.exchangerate-api.com/docs/free https://www.exchangerate-api.com/terms INR 2021-03-31 1617148801 0.301281

160 rows × 7 columns

Working with SQL


In [17]: !pip install mysql.connector

Processing c:\users\91842\appdata\local\pip\cache\wheels\57\e4\98\5feafb5c393dd2540e44b064a6f95832990d543e5b4f53ea8f\mysql_connector-2.2.9-cp38-cp38-win_amd64.whl
Installing collected packages: mysql.connector
Successfully installed mysql.connector

In [18]: import mysql.connector

In [20]: conn = mysql.connector.connect(host='localhost',user='root',password='',database='world')

In [27]: df = pd.read_sql_query("SELECT * FROM countrylanguage",conn)

In [28]: df

Out[28]: CountryCode Language IsOfficial Percentage

0 ABW Dutch T 5.3

1 ABW English F 9.5

2 ABW Papiamento F 76.7

3 ABW Spanish F 7.4

4 AFG Balochi F 0.9

... ... ... ... ...

979 ZMB Tongan F 11.0

980 ZWE English T 2.2

981 ZWE Ndebele F 16.2

982 ZWE Nyanja F 2.2

983 ZWE Shona F 72.1

984 rows × 4 columns

In [ ]: ​

You might also like