<jupyter_start><jupyter_text>90 minsyesterday- define variables, basic data types, built-in functions- `import`, list, reading files, plot,  - repeat with for loop- control conditions- function<jupyter_code>!ls data
import glob
help(glob)
help(glob.glob)
glob.glob('data/*')
file_list = glob.glob('data/*.csv')
len(file_list)
file_list
#for item in iterative_structure:
#    print(item)
for file_name in file_list:
    print(file_name)
import pandas as pd
for file_name in file_list:
    data = pd.read_csv(file_name)
    columns = list(data)
    number_of_cols = len(columns)
    print(file_name, number_of_cols)
number_of_cols
# if conditionA:
#     do something A
#     
# elif conditionC:
#     do something C
#     
# else:
#     do something B
for file_name in file_list:
    data = pd.read_csv(file_name)
    if 'americas' in file_name:
        print(file_name, len(list(data)))
    elif 'europe' in file_name:
        print(file_name, len(data.index))
    elif 'all' in file_name:
        print(file_name)
    else:
        #print('skip')
        pass
# def function_name(arg1, arg2, ...):
#     do something 
#     return value1, value2, value3, ...
x, y, z = 1, 3, 18
print(x, y, z)
# define a function
def process(x):
    square = x * x
    cubic = square * x
    return square, cubic
process(2)
a, b = process(2)
print(a, b) # 4 8
r = process(2)
r
type(r)
def process_3(x):
    return x*x, x**3, x**4
r3 = process_3(2)
r3
type(r3)
print(dir(r3))
print(dir(file_list))
def process_no(x):
    square = x * x
r_no = process_no(2)
print(r_no)
None # null
True
False
#import numpy
#numpy.array(1)/numpy.array(0)
for item in r3:
    print(item)
def count_down(x, label):
    timer = x
    while timer > 0 and label=='count':
        print('count down', timer)
        timer = timer - 1
    return
count_down(5, 'count')
rcd = count_down(5, 'skip')
print(rcd)
help(range)
def count_down_for(x):
    for timer in range(x, 0, -1):
        print('count down', timer)
count_down_for(5)
range(5, 0, 1)
list(range(5, 0, -1))
index_list = list(range(0, len(r3), 1))
print(index_list)
print(r3)
for index, value in zip(index_list, r3):
    print(index, value)<jupyter_output>0 4
1 8
2 16<jupyter_text>summary:- for vs while loops- if elif else- how to define a function<jupyter_code>import time
import datetime

interval = 1 * 60 # 1 mins
wait_time = 30 * 60 # 30 mins
print('current time is', datetime.datetime.now())
for i in range(int(wait_time/interval)):
    time.sleep(interval)
    print('waited for {} seconds'.format(interval))
    print('iteration', i, 'current time is', datetime.datetime.now())
    
print('total wait time is {} seconds'.format(wait_time))
import time
import datetime

def timer_count_down(interval_m, wait_time_m):
    interval = interval_m * 60 # mins --> seconds
    wait_time = wait_time_m * 60 # mins --> seconds
    print('current time is', datetime.datetime.now())
    for i in range(int(wait_time/interval)):
        time.sleep(interval)
        print('waited for {} seconds'.format(interval))
        print('iteration', i, 'current time is', datetime.datetime.now())

    print('total wait time is {} seconds'.format(wait_time))
    
timer_count_down(5/60, 1)
import os.path, os
!pwd
os.getcwd()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13282208588957056, 'fraction_numerical': 0.022085889570552148, 'mean_word_length': 3.705627705627706, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '399345', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 1213, 'n_tokens_neox': 1168, 'n_words': 330, 'path': 'workshop/python II.ipynb', 'repo_name': 'zdshaoteach/2022-03-28-upr-online', 'size': '3260'}