1 of 16

HandsOn Session Python Project

2 of 16

Kurnia Anwar Ra’if

A Highly-motivated Data Scientist

Senior Data & AI Platform - PT. Mastersystem Infotama Tbk

Data Scientist @ PT. KitaLulus International

Data Scientist @ PT. Sharing Vision– BRI Consultant

Software Engineering @ PT. AILIMA Geothermal

Mentor DS/BI/AI-ML - @ Dibimbing.id

3 of 16

Outline :

  • Refreshment
  • Flowchart
  • Mini App - HandsOn

4 of 16

  • Refreshment

5 of 16

6 of 16

Conditional Statements (if, elif, else)

Summary :

- if: checks the first condition

- elif: checks additional conditions

- else: runs if none of the above conditions are true

These are essential for building decision-making logic in your Python programs.

The if statement checks whether a condition is True. If it is, the indented block of code under it will be executed.

elif (else if) Used to check another condition if the previous if condition was False. You can have multiple elif blocks.

The else block is executed when none of the previous conditions are True.

7 of 16

Defining and calling functions

  • Function adalah blok kode yang dirancang untuk menjalankan tugas tertentu. Function juga bisa disebut method().
  • Tujuan utama: mengurangi pengulangan kode, mempermudah perawatan, dan meningkatkan keterbacaan.
  • Dalam Python, fungsi didefinisikan menggunakan def

8 of 16

Parameters and Return

Multiple parameters & return multiple values

9 of 16

  • Flowchart

10 of 16

Flowchart

11 of 16

Flowchart : Mini App

12 of 16

Hands on

13 of 16

Brief Assignment

14 of 16

Buat program Mini App dengan ketentuan :

1. Buat program untuk meng-generate file log sensor IoT (log_sensor.csv) yang berisi kolom:

• waktu (range waktu tertentu, misalnya dari jam 08:00 sampai 12:00 dengan interval 10 menit)

• suhu (25–35 °C)

• kelembaban (40–70 %)

• tekanan (1008–1015 hPa)

• co2 (380–600 ppm)

• cahaya (50–500 lux)

2. Simpan hasil generate ke file .csv dengan format tabular.

15 of 16

3. Spesifikasi Program:

a. Gunakan File Handling manual (open + .split()) untuk membaca file:

Tampilkan isi file mentah.

Parsing isi file menjadi list of lists sebelum diubah ke DataFrame.�b. Konversi data ke Pandas DataFrame dengan kolom yang sesuai.�c. Hitung dan tampilkan hasil analisis:

Rata-rata suhu, kelembaban, tekanan, CO₂, cahaya

Nilai maksimum & minimum dari setiap sensor

4. Kembangkan menjadi mini app sederhana dengan ketentuan:

Gunakan function dengan nama berikut untuk:

- generate_sensor_data() → menghasilkan data sesuai rentang waktu

- save_to_csv() → menyimpan data ke file

- analyze_data() → membaca file & menampilkan hasil analisis (rata-rata, min, max)

- Program utama (main) memanggil semua function tersebut.

16 of 16

Thank you

https://www.linkedin.com/in/anwaraif/

kurniafreelancer@gmail.com