HandsOn Session Python Project
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
Outline :
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.
Defining and calling functions
Parameters and Return
Multiple parameters & return multiple values
Flowchart : Mini App
Hands on
Brief Assignment
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.
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.
Thank you
https://www.linkedin.com/in/anwaraif/
kurniafreelancer@gmail.com