cheatSheet

Last Updated on May 15, 2023 by mishou

Work in progress.

1. Basics 1 Self-taught learning
2. Basics 2 Making your cheat sheets
3. Basics 3 Google Colaboratory
4. Basics 4 Mathematical operators
5. Basics 5 Autofill and List Comprehensions
6. Basics 6 Tables
7. Basics 7 Classes and Objects
8. Basics 8 Pivot Tables
9. Basics 9 Sample Data Sets
10. Basics 10 Flash Fill
11. Basics 11 Charts
12. Basics 12 Loops
13. Basics 13 Funcitons
14. Basics 14 Macros

I. The tables

These are the sample datasets for the lectures.

1.HTML tables

These are sample datasets for learning Python with Cheat Sheets.

Table 1

idenglishjapanesenationalitydepartmentclassesgender
117.875.6japanliterature2male
264.453.3nepalliterature2male
386.731.1nepalliterature1male
46062.2indonesialiterature2male
542.280japanliterature1male
633.375.6japanliterature1male
728.960japanliterature2male
853.388.9japanliterature1male
942.260japanliterature1male
104080japanliterature1male
1133.382.2japanliterature2female
1224.475.6chinaeconomics2male
1357.880japanliterature1male
1462.286.7japanliterature2male
1562.271.1japanliterature2male
1662.286.7japanliterature1male
174068.9japanliterature1male
1884.457.8nepalliterature1male
1973.384.4chinaliterature2female
2028.955.6japaneconomics2male
2164.431.1nepalliterature2male
2271.175.6japanliterature2female
2337.851.1vietnamliterature1female
2433.340vietnamliterature2male
2584.433.3nepalliterature2male
2677.877.8nepalliterature1male
2735.673.3japanliterature2female
2831.180japanliterature1male
2924.464.4japaneconomics1male
3026.753.3japanliterature2male
3166.728.9nepalliterature1male
3226.766.7japaneconomics1female
3353.382.2japanliterature2male
3426.760chinaliterature2male
3562.282.2japanliterature2male
3626.780japaneconomics1male
3771.160vietnamliterature2male
3833.331.1indonesialiterature1male
3951.175.6japanliterature2female
4053.388.9japanliterature2male
4124.460japaneconomics2male
4231.142.2vietnamliterature1male
4333.340vietnamliterature1female
4446.777.8japanliterature1female
458057.8nepalliterature2male
4693.355.6nepalliterature2male
476080japanliterature2male
4855.675.6japanliterature1male
4935.691.1japanliterature2male
5051.171.1japanliterature1male
5126.760japanliterature2male
5224.468.9japanliterature2male
5353.384.4japanliterature2male
5462.282.2japanliterature2male
5564.482.2japanliterature2female
5631.164.4japanliterature2male
5737.868.9chinaliterature2male
5833.362.2japanliterature2male
5957.844.4vietnamliterature2female
6082.277.8nepalliterature2male
614080chinaliterature2male
626026.7vietnamliterature1male
6328.942.2vietnamliterature1male
6451.168.9japanliterature1female
6533.364.4japaneconomics2male
6655.680japaneconomics1male
678037.8nepaleconomics2male
6835.635.6nepaleconomics1male
6928.973.3japaneconomics2male
7028.957.8chinaeconomics2female
7135.653.3japaneconomics2male
7215.684.4japaneconomics2male
7326.764.4japaneconomics1male
7428.962.2japaneconomics1male
7515.660japaneconomics2male
7637.871.1japaneconomics2male
7731.142.2japaneconomics2male
7846.775.6japaneconomics1male
7931.171.1japaneconomics2male
8035.668.9japaneconomics1male
8122.255.6japaneconomics1male
8215.675.6japaneconomics1male
832071.1japaneconomics2male
8428.948.9japaneconomics2male
8548.964.4japaneconomics1male
8626.771.1japaneconomics2male
8731.128.9japaneconomics2male
8822.260japaneconomics1male
8964.486.7japaneconomics1female
9024.475.6japaneconomics2male
912051.1japaneconomics2male
9233.351.1japaneconomics1male
9353.386.7japaneconomics2male
9488.933.3nepaleconomics2male
952080japaneconomics2male
9628.931.1japaneconomics1male
9728.942.2japaneconomics2male
9848.940nepaleconomics2male
9944.455.6japaneconomics2male
10028.957.8vietnameconomics2female
10124.460japaneconomics1male
10255.666.7vietnameconomics2female
10362.255.6vietnameconomics2female
10435.635.6vietnameconomics2male
10551.153.3vietnameconomics2male
10646.744.4vietnameconomics2male
10746.771.1japaneconomics1female
10828.975.6japaneconomics1male
10937.877.8chinaeconomics1male
11048.986.7japaneconomics2female
11146.773.3japaneconomics2male
11226.768.9japaneconomics1male
11346.773.3japaneconomics2male
11442.257.8japaneconomics1male
11555.662.2japaneconomics2male
11624.486.7japaneconomics1male
11731.173.3japaneconomics2male
11842.268.9japaneconomics2male
11986.764.4nepaleconomics1male
12042.224.4nepaleconomics1male
12148.955.6chinaeconomics2male
12231.166.7chinaeconomics2male
12331.168.9japaneconomics2male
12446.780japaneconomics1male
12553.371.1japaneconomics1male
12651.188.9japaneconomics2female
12737.873.3vietnameconomics2female
12835.682.2japaneconomics2male
12922.266.7japaneconomics1male
13035.648.9japaneconomics1male
1314073.3japaneconomics1male
13271.184.4japaneconomics2female
13364.453.3nepaleconomics2male
1348053.3nepaleconomics1male
13575.668.9nepaleconomics2male
13631.171.1vietnameconomics2male
13726.773.3japaneconomics1male
13822.240vietnameconomics2male
13973.377.8vietnameconomics2female
14022.244.4vietnameconomics1male
14186.780chinaeconomics2male
1424046.7japaneconomics1male
14326.753.3japaneconomics2male
14462.255.6vietnameconomics1female
14537.877.8chinaeconomics2female
14633.355.6japaneconomics1male
14762.277.8japaneconomics1male
14842.275.6japaneconomics1male
1492062.2japaneconomics2male
15024.460japaneconomics1male
15122.268.9japaneconomics2male
15237.857.8japaneconomics2male
15333.373.3japaneconomics2female
15433.364.4japaneconomics2male
1556057.8indonesiaeconomics1male
15624.444.4japaneconomics1male
1576080japaneconomics2male
15831.166.7japaneconomics2male
15935.664.4japaneconomics1female
16028.960japaneconomics2male
16157.860nepaleconomics2male
16248.960nepaleconomics2male
16342.280japaneconomics2female
1642051.1japaneconomics1male
16548.982.2japaneconomics2male
16628.960japaneconomics1male
16722.242.2japaneconomics2male
1684091.1vietnameconomics2female
16933.371.1vietnameconomics2male
17031.133.3japaneconomics1male
17135.664.4japaneconomics1male
17244.420nepaleconomics1male
1736022.2nepaleconomics1male
17442.240japaneconomics2male
17531.164.4japaneconomics1male
1762062.2japaneconomics1male
17742.288.9japaneconomics1male
17824.448.9japaneconomics1male
17946.791.1japaneconomics2male
18033.364.4japaneconomics2male
18126.744.4japaneconomics2male
1822060japaneconomics1male
1834062.2japaneconomics1male
1844057.8japaneconomics2female
18553.328.9nepaleconomics1male
18633.384.4japaneconomics1male
18724.451.1japaneconomics1male
18842.253.3japaneconomics1male
18944.488.9japaneconomics2female
1904080japaneconomics2female
19117.853.3japaneconomics2male
19248.982.2japaneconomics2male
19328.975.6japaneconomics1male
19437.873.3japaneconomics1male
19584.428.9nepaleconomics2male
19666.755.6nepaleconomics2male
19744.480chinaeconomics2male
19857.848.9vietnameconomics1female
19986.726.7vietnameconomics2male
20024.468.9japaneconomics2male

Table 2

idclassesattendance01attendance02attendance03attendance04attendance05attendance06attendance07attendance08attendance09attendance10attendance11attendance12attendance13attendance14attendance15
1bew1110100100001100
2bew1111111110011111
3bew1111111111000011
4bew1111111111111111
5bew1111011111110010
6bew1111010000000000
7bew1111111111111111
8bew1111011111111111
9bew1111111110110101
10bew1111111111111111
11bew1111111111111100
12bew1111111111111111
13bew1111111111110111
14bew1111111111011111
15bew1010000000000000
16bew1111111111111011
17bew1111111111111111
18bew1111111111111111
19bew1111111111111111
20bew1111111110111111
21bew1111111111111111
22bew1111111111111111
23bew1111111111111101
24bef4111111111111111
25bef4110101101101011
26bef4111111111111011
27bef4111111111111111
28bef4111111111111111
29bef4111111111111111
30bef4111111111101001
31bef4111111111100011
32bef4101111111111111
33bef4111111111111111
34bef4110111101111000
35bef4110011011101111
36bef4110001111111111
37bef4000011111111110
38bef4111011111111111
39bef4111111111110111
40bef4111111111111111
41bef4111111111111111
42bef4111111111111111
43bef4111111111111111
44bef4100011001111111
45bef4111111111111111
46cew3111111111111111
47cew4111011111111111
48cew5111111111111111
49cew6111111111111111
50cew7111111111111111
51cew8101111111111111
52cew9111111111011111
53cew10111111111111011
54cew11111111111111111
55cew12111111111111101
56cew13111111111111111
57cew14111111111111111
58cew15111111111111111
59cew16111111111111111
60cew17111111111111111
61cew18111111111111111
62cew19111111111111111
63cew20111011111111111
64cew21111111111111111
65cew22111110110111111
66cew23111011111111111
67cew24111111111000111
68cew25111100110101111
69cew26111111111101111
70cew27111111101111101
71cew28111111111100111
72cew29111111101111111

Table 3

idclassesres1res2res3res4res5res6res7
01bew1strongly agreestrongly agreemoderatestrongly agreestrongly agreestrongly agreestrongly agree
12bew1strongly agreestrongly agreemoderatestrongly agreestrongly agreestrongly agreestrongly agree
23bew1strongly agreestrongly agreemoderatestrongly agreestrongly agreestrongly agreestrongly agree
34bew1strongly agreestrongly agreemoderateagreestrongly agreeagreestrongly agree
45bew1strongly agreeagreemoderatestrongly agreestrongly agreeagreestrongly agree
56bew1agreeagreeeasyagreeagreeagreeagree
67bew1agreeagreemoderateagreeagreeagreeagree
78bew1agreeagreemoderateagreeagreeagreeagree
89bew1strongly agreestrongly agreevery difficultstrongly agreestrongly agreestrongly agreestrongly agree
910bew1strongly agreestrongly agreemoderatestrongly agreestrongly agreestrongly agreeagree
1011bew1strongly agreestrongly agreemoderatestrongly agreestrongly agreestrongly agreestrongly agree
1112bew1strongly agreestrongly agreedifficultstrongly agreeagreestrongly agreestrongly agree
1213bew1strongly agreestrongly agreedifficultstrongly agreestrongly agreestrongly agreestrongly agree
1314bew1strongly agreestrongly agreedifficultstrongly agreestrongly agreestrongly agreestrongly agree
1415bew1strongly agreeagreedifficultstrongly agreeagreeagreestrongly agree
1516bew1strongly agreeagreedifficultagreeagreestrongly agreestrongly agree
1617bew1strongly agreestrongly agreedifficultstrongly agreestrongly agreestrongly agreestrongly agree
1718bew1agreeagreemoderateneutralagreeagreeagree
1819bew1strongly agreestrongly agreedifficultagreeagreestrongly agreeagree
1920bew1strongly agreestrongly agreedifficultagreeagreestrongly agreeagree
2021bef4strongly agreestrongly agreeeasystrongly agreestrongly agreestrongly agreestrongly agree
2122bef4agreeagreeeasyneutralagreeagreestrongly agree
2223bef4strongly agreestrongly agreevery easystrongly agreeagreestrongly agreestrongly agree
2324bef4strongly agreestrongly agreeeasystrongly agreestrongly agreestrongly agreeagree
2425bef4agreeneutralmoderateagreeneutralneutralagree
2526bef4strongly agreeagreemoderatestrongly agreestrongly agreestrongly agreestrongly agree
2627bef4strongly agreestrongly agreedifficultstrongly agreestrongly agreestrongly agreestrongly agree
2728bef4strongly agreestrongly agreedifficultagreestrongly agreestrongly agreestrongly agree
2829bef4strongly agreestrongly agreedifficultagreeagreestrongly agreestrongly agree
2930bef4strongly agreestrongly agreemoderatestrongly agreestrongly agreestrongly agreestrongly agree
3031bef4agreedisagreemoderateagreedisagreestrongly agreestrongly agree
3132bef4agreeagreedifficultneutralneutralagreestrongly agree
3233bef4agreeagreevery difficultagreeagreeagreeagree
3334bef4disagreeagreevery difficultneutralstrongly agreestrongly agreestrongly agree
3435bef4agreeagreedifficultneutralagreeagreeagree
3536bef4agreeneutraleasyagreeagreeagreestrongly agree
3637bef4agreeagreemoderateneutralneutralagreeagree
3738bef4strongly agreeagreemoderateagreeagreeagreeagree
3839bef4agreestrongly agreemoderateneutralagreedisagreeneutral
3940bef4strongly agreestrongly agreemoderatestrongly agreestrongly agreestrongly agreestrongly agree

2.CSV raw data

These are the links to the CSV raw data pages. The data are the same as the data above.

Table 1

https://pastebin.com/raw/cSZ8pYWh

Table 2

https://pastebin.com/raw/19gskrJK

Table 3

https://pastebin.com/raw/DiqmYyz3

II. Retrieving data using Google Sheets

Reading the first table of this page with Google Sheets:

=IMPORTHTML("http://www.mishou.be/2023/03/27/python-basics-8-sample-data-sets/","table",1)

Reading the raw data at https://pastebin.com/raw/cSZ8pYWh:

=IMPORTDATA("https://pastebin.com/raw/cSZ8pYWh")

You can see all the tables here:

https://docs.google.com/spreadsheets/d/1gm-tvvbq8QZwgXBHVFwBuEAQRmNpzH1lPD4Eja0cx0E/edit?usp=sharing

III. How to retrieve CSV data as DataFrame using Polars in Python

Polars utilizes a columnar data structure, where data is organized and stored by columns rather than rows. So Polars doesn’t have any index.

You can see some sample code in Google Colaboratory:

https://colab.research.google.com/drive/1jNj4GpUfR2mYJjffN2KSZFRZzv5xfwID?usp=sharing

IV. How to retrieve CSV data as DataFrame using Pandas in Python

1. Reading HTML tables with Pandas

table annoted

You can read the tables with Pandas and show the first table with the following codes:

import panda as pd
df = pd.read_html('http://www.mishou.be/2021/10/04/pythonr-sample-data-for-data-analysis/')
df[0]

You can see the scripts here:

https://colab.research.google.com/drive/1etXZ-2-RVrCuc3fD6L-8HS6HeeUVQrzS?usp=sharing

2. Reading CSV raw data with Pandas

You can read CSV raw data with the following codes:

import pandas as pd
df = pd.read_csv('https://pastebin.com/raw/cSZ8pYWh')
df.head()

You can see the scripts here:

https://colab.research.google.com/drive/1nzk_YaALD52ASJe0FyOKFuEj-2zHNhbb?usp=sharing

V. How to retrieve tables using Classes and Objects in Python

You can also use Classes and Objects to handle CSV data.

Loading the data:

# load data from url
import csv
import requests

CSV_URL = 'https://pastebin.com/raw/cSZ8pYWh'

with requests.Session() as s:
    download = s.get(CSV_URL)

    decoded_content = download.content.decode('utf-8')

    cr = csv.reader(decoded_content.splitlines(), delimiter=',')
    
    my_list = list(cr)
    for row in my_list:
        print(row)
# remove the header
my_list.pop(0)

Creating a class:

# create a class
class Student:
    
    def __init__(self, number, english, japanese, nationality, department, classes, gender):
      self.number = number
      self.english = english
      self.japanese = japanese
      self.nationality = nationality
      self.department = department
      self.classes = classes
      self.gender = gender

    def average(self):
        return (round((self.english + self.japanese)/2, 2))

    def report(self):
        print(f"Your number: {self.number}, English: {self.english}, Japanese: {self.japanese}, Average: {self.average()}")

Creating a list of objects:

# create a list of objecst
student_list = []
for id, english, japanese, nationality, department, classes, gender in my_list:
   # covert types
   id = int(id)
   english = float(english)
   japanese = float(japanese)
   nationality = str(nationality)
   department = str(department)
   classes = str(classes)
   gender = str(gender)
   # create Student instances and append them to a list
   student_list.append(Student(id, english, japanese, nationality, department, classes, gender))

You can see all the scripts here:

https://colab.research.google.com/drive/1B84Ykq1FfuNZjl_znLgoXzjz4QRUkfPr?usp=sharing

By mishou

Leave a Reply

Your email address will not be published. Required fields are marked *