Last Updated on May 4, 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. If functions in Google Sheets
Sample 1

Sample 2

At A1
=importdata(“https://pastebin.com/raw/cSZ8pYWh”)
At H2
=average(B2,C2)
At I2
=if(H2<30,”Failed”,(if(H2<50,”C”,(if(H2<70,”B”,(if(H2<90,”A”,(if(H2<=100,”S”)))))))))
You can see the sheets here:
https://docs.google.com/spreadsheets/d/1fbs69LCn2SAPdcQQ_nehb8vn-ETL2x2uQNePp7M5A9k/edit?usp=sharing
II. If statements in Python
Sample 1

Sample 2-1 Adding Failed or Passed

You will get an error if you replace the code above with the following code.
(df. assign(average = lambda row: (row.english + row.japanese)/2, grade = lambda x: 'Failed' if x.average < 60 else 'Passed') )
The error is caused by the comparison row.average < 60 in the grade lambda function. x.average is a pandas Series and it cannot be directly compared with a scalar value.
Sample 2-2: Adding grades with assign() + lambda + np.where

Sample 2-3: Adding grades with function() + assign() + apply()

You can see the scripts here:
https://colab.research.google.com/drive/1INbCGqUMdlbQBEjOSIRWnmNZkEHyYbSS?usp=sharing
You can learn more here: