<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Austin Oketch</title>
    <description>The latest articles on DEV Community by Austin Oketch (@austin_oketch).</description>
    <link>https://dev.to/austin_oketch</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3008248%2F52abee9d-32f7-4779-9a1f-18d240a20239.jpg</url>
      <title>DEV Community: Austin Oketch</title>
      <link>https://dev.to/austin_oketch</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/austin_oketch"/>
    <language>en</language>
    <item>
      <title>A Beginner's Guide to Python,APIs and Pandas</title>
      <dc:creator>Austin Oketch</dc:creator>
      <pubDate>Tue, 12 Aug 2025 05:34:10 +0000</pubDate>
      <link>https://dev.to/austin_oketch/a-beginners-guide-to-pythonapis-and-pandas-3j8d</link>
      <guid>https://dev.to/austin_oketch/a-beginners-guide-to-pythonapis-and-pandas-3j8d</guid>
      <description>&lt;p&gt;Ingesting,processing and analyzing data from external sources has become common in Software Development.This is mainly achieved via the use of APIs.In this guide we'll talk about the process of building a basic but powerful data ingestion script using Python.&lt;/p&gt;

&lt;p&gt;We'll be obtaining cryptocurrency pair prices from the publicly available Binance API and filter only responses we're interested in.This will be achieved by utilizing two popular Python libraries: &lt;strong&gt;pandas&lt;/strong&gt; for data manipulation and &lt;strong&gt;requests&lt;/strong&gt; for handling HTTP communication.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Complete Python Script&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import pandas as pd
import requests

# Configuration: Define constants for maintainability
BASE_URL = 'https://api.binance.com'
TARGET_PAIRS = ['BTCUSDT','ETHBTC','ETHUSDT','SOLUSDT']

def get_latest_prices():
    """
    Fetches, parses, and filters price data from the Binance API.
    """
    # 1. Construct the full API endpoint URL
    endpoint = f'{BASE_URL}/api/v3/ticker/price'

    # 2. Execute the HTTP GET request
    response = requests.get(endpoint)
    # For production, add error handling: response.raise_for_status()

    # 3. Deserialize the JSON response into a Python object
    data = response.json()

    # 4. Load the raw data into a pandas DataFrame
    price_df = pd.DataFrame(data)

    # 5. Filter the DataFrame using boolean masking
    filtered_df = price_df[price_df['symbol'].isin(TARGET_PAIRS)]

    print(filtered_df)
    return filtered_df

# 6. Define the script's entry point
if __name__ == "__main__":
    get_latest_prices()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now lets break down the script step by step.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Configuration and Structure&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;BASE_URL = 'https://api.binance.com'
TARGET_PAIRS = ['BTCUSDT','ETHBTC','ETHUSDT','SOLUSDT']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We define BASE_URL and TARGET_PAIRS at the top to separate configuration and logic making code easier to read and update without touching core function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Interface with API using requests&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The requests library is utilized to handle HTTP transaction with the Binance API.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;endpoint = f'{BASE_URL}/api/v3/ticker/price'
response = requests.get(endpoint)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The requests.get() packages the server response containing status codes, headers and data payload into a single response object stored in response variable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Deserializing the JSON Payload&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The response(payload) from most modern APIs is formatted as JSON(JavaScript Object Notation).&lt;/p&gt;

&lt;p&gt;Even though this is text-based and readable it is not a Python native object.It therefore requires to be parsed and "deserialized".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;data = response.json()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Structuring Data with pandas&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The data variable is now a large list of dictionaries.&lt;br&gt;
We use pandas to transform this raw data into optimized, tabular structure called a DataFrame.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;price_df = pd.DataFrame(data)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A DataFrame is an in-memory two-dimensional table with labeled axes(rows and columns).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Filtering with Boolean Masking&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;filtered_df = price_df[price_df['symbol'].isin(TARGET_PAIRS)]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;price_df['symbol']:&lt;/strong&gt; First you select the symbol column of the DataFrame which returns a pandas *&lt;em&gt;Series *&lt;/em&gt; object which is a single column of the DataFrame.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;.isin(TARGET_PAIRS):&lt;/strong&gt; You then call the .isin() method on this Series.The method performs a fast element check, returning a series of Boolean values.True means symbol in that row exists in &lt;strong&gt;TARGET_PAIRS&lt;/strong&gt; list and vice versa.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;price_df[...]&lt;/strong&gt;: Finally you use this boolean Series as a mask to index the original price_df.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is known as boolean masking.It evaluates the mask and returns a new DataFrame containing only rows where the mask value is True.&lt;/p&gt;

&lt;p&gt;We have now successfully completed implementing a data ingestion pipeline.You can later add Robust Error handling and Automation e.g., using scheduler like cron to create a historical price log.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>api</category>
      <category>pandas</category>
      <category>python</category>
    </item>
    <item>
      <title>Decoding Data Engineering: 15 Core Concepts That Power Modern Data Platforms</title>
      <dc:creator>Austin Oketch</dc:creator>
      <pubDate>Mon, 11 Aug 2025 06:04:32 +0000</pubDate>
      <link>https://dev.to/austin_oketch/decoding-data-engineering-15-core-concepts-that-power-modern-data-platforms-fi5</link>
      <guid>https://dev.to/austin_oketch/decoding-data-engineering-15-core-concepts-that-power-modern-data-platforms-fi5</guid>
      <description>&lt;p&gt;&lt;strong&gt;Data Engineering&lt;/strong&gt; is the invisible backbone to the data-driven space.Even though Data Scientists and Data Analysts get the spotlight for the insightful dashboards and predictive models, data engineers are key architects of the data-driven ecosystem via the provision of robust and reliable data pipelines.&lt;/p&gt;

&lt;p&gt;This Architecture consists of a collection of powerful concepts which when combined together in turning raw data into purposeful and insightful information.&lt;/p&gt;

&lt;p&gt;Some of these concepts include:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Chapter 1: How Data is Extracted and Transformed&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Data Engineering is basically about moving data from a source to a destination.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Stream and Batch Ingestion.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Both of these are fundamental steps in data ingestion.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stream Ingestion&lt;/strong&gt; is processing of data event by event in near real time as it is generated.This is very important for time sensitive systems and applications like a real-time analytics dashboard, monitoring system logs and fraud detection.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Batch Ingestion&lt;/strong&gt; is the gathering, processing and moving data in large scheduled chunks at a go.This is highly efficient for large volumes of data and application that don't require immediate data like generating reports.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. ELT and ETL&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ELT(Extract, Load, Transform)&lt;/strong&gt; is the modern cloud-native approach.You extract data and immediately load it in a scalable cloud data warehouse.The transformation logic is then done in the warehouse via tools like SQL.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ETL(Extract,Transform,Load)&lt;/strong&gt; is the traditional approach.You extracted data from a source, transforming it into a clean, structured dataset on a separate processing server e.g, Spark Cluster and loading into into a data warehouse.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Change Data Capture(CDC)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Change Data Capture allows you to identify only the changes (insert, update, and delete operations) rather than re-ingesting a table with many rows merely to obtain a handful that changed.&lt;/p&gt;

&lt;p&gt;It does this by scanning write-ahead logs, or database transaction logs, and utilizing Debezium and other CDC tools to record operational changes. Because of this, the entire pipeline is effective in allowing OLTP databases and OLAP systems to synchronize in almost real-time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Chapter 2: Data Storage&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4.OLAP and OLTP&lt;/strong&gt;&lt;br&gt;
These many database system types were created with various goals in mind.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;OLTP (Online Transaction Processing)&lt;/strong&gt; systems, such as ATMs and aircraft reservation systems, are designed to process large amounts of reads and writes in a fast and reliable manner.&lt;/p&gt;

&lt;p&gt;Systems designed for complicated queries over vast amounts of historical data, such as a dashboard displaying sales trends over time, are known as &lt;strong&gt;OLAP (Online Analytical Processing)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Columar and Row-based Storage&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Columnar-based Storage&lt;/strong&gt; stores all values in a single column.This makes processing analytical queries incredibly fast(used by OLAP systems like Snowflake,Redshift).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Row-based Storage&lt;/strong&gt; stores values belonging to a single record together in rows.(used by OLTP databases like PostgreSQL,MariaDB).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6.Partitioning&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is the splitting of large tables into smaller more manageable physical chunks based on a key.This is done to improve performance,scalability and manageability of a database.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Chapter 3: Building Robust and Reliable Data Pipelines&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. Idempotency&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;An operation is idempotent if it has same outcome after being ran once.e.g, a system that processes payment transactions.&lt;/p&gt;

&lt;p&gt;If it fails during the processing and restarts other payments can be reprocessed.An idempotent design ensures one is not charged two times by checking if the transaction ID exists before inserting a new record.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Retry Logic and Dead Letter Queues(DLQs)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dead Letter Queues (DLQs) and Retry Logic&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Retry Logic&lt;/strong&gt; is a software fallback mechanism that retries an operation once a brief error occurs in order to handle operational failures.&lt;/p&gt;

&lt;p&gt;In order to avoid unsuccessful messages from obstructing the queue and enabling the examination of unsuccessful messages, the &lt;strong&gt;Dead Letter Queue&lt;/strong&gt; serves as a holding space for messages that cannot be delivered to recipients or processed successfully.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;9. Backfilling and Reprocessing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Backfilling&lt;/strong&gt; refers to processing historical data through a pipeline to either append or update pipeline with information.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reprocessing&lt;/strong&gt; is the process of running a pipeline or a portion of it again in order to add new data, apply changes, or fix mistakes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Chapter 4: Workflow Orchestration and Stream Processing&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;DAGs and Workflow Orchestration&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The data pipeline's blueprint is called a DAG (Directed Acyclic Graph).It specifies dependencies (directed edges) and tasks (nodes), making sure they execute in the right order and avoid becoming trapped in acyclic (infinite) loops, like Apache Airflow.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;11. Windowing in Streaming&lt;/strong&gt;&lt;br&gt;
This allows computations on specified intervals by dividing a continuous data stream into manageable pieces known as windows.&lt;/p&gt;

&lt;p&gt;Common types include:&lt;br&gt;
&lt;strong&gt;Tumbling Window:&lt;/strong&gt; Fixed-size, non-overlapping windows.&lt;br&gt;
&lt;strong&gt;Sliding Window:&lt;/strong&gt; Fixed-size, overlapping windows.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Chapter 5: Advanced System Design and Governance&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;12. CAP Theorem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This theorem states that a distributed data store can only offer two of the following guarantees, according to a fundamental law of distributed systems:&lt;br&gt;
&lt;strong&gt;Availability:&lt;/strong&gt; Every database request is answered, even if it isn't the most recent data.&lt;br&gt;
&lt;strong&gt;Partition Tolerance:&lt;/strong&gt; The system keeps running even when there are network partitions (communication breakdowns between nodes).&lt;br&gt;
&lt;strong&gt;Consistency:&lt;/strong&gt; Every node in the system sees the same data at the same time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;13. Data Governance&lt;/strong&gt;&lt;br&gt;
This is the framework of policies, rules and standards for managing data.&lt;/p&gt;

&lt;p&gt;It is involved in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Data Quality: Data completeness and accuracy.&lt;/li&gt;
&lt;li&gt;Data Lineage: Data origin.&lt;/li&gt;
&lt;li&gt;Access Control: Entities allowed to view and utilize data.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;14. Time Travel and Data Versioning&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;These are techniques that allows users to access and restore previous states of data facilitating historical analysis and error recovery.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;15. Distributed Processing Concepts&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is the processing of dividing a computational task among multiple computers(nodes) in a network allowing handling of large complex problems by utilizing combined power of multiple machines.&lt;/p&gt;

</description>
      <category>dataengineering</category>
      <category>programming</category>
      <category>python</category>
    </item>
    <item>
      <title>Data Platform for Analyzing Kenya’s Food Prices and Inflation Trends.</title>
      <dc:creator>Austin Oketch</dc:creator>
      <pubDate>Sun, 10 Aug 2025 10:34:10 +0000</pubDate>
      <link>https://dev.to/austin_oketch/data-platform-for-analyzing-kenyas-food-prices-and-inflation-trends-4o6n</link>
      <guid>https://dev.to/austin_oketch/data-platform-for-analyzing-kenyas-food-prices-and-inflation-trends-4o6n</guid>
      <description>&lt;p&gt;In this article we will be turning a raw &lt;a href="https://data.humdata.org/dataset/wfp-food-prices-for-kenya" rel="noopener noreferrer"&gt;dataset&lt;/a&gt; containing Kenya food prices in different regions across the country over the years.We'll achieve this via an Extraction, Transformation and Loading pipeline building a complete data pipeline for analysis.&lt;/p&gt;

&lt;p&gt;We'll go from a &lt;a href="https://data.humdata.org/dataset/wfp-food-prices-for-kenya" rel="noopener noreferrer"&gt;CSV&lt;/a&gt; file to a clean, query-optimized database and a beautiful, interactive Grafana dashboard.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PROJECT ARCHITECTURE&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Our data pipeline for analysis will look like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Source&lt;/strong&gt;: A World Food Programme CSV file containing Kenya Food Prices in different Kenyan provinces and regions since 2006.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ETL Engine&lt;/strong&gt;: A Python script utilizing Pandas for the Extraction, Transformation and Loading of the extracted data into designated database for analysis.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data Warehouse&lt;/strong&gt;: A PostgreSQL database modeled with a Star Schema&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Visualization Layer&lt;/strong&gt;: A Grafana dashboard that queries the database to get insights.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We use a &lt;strong&gt;Star Schema&lt;/strong&gt; which contains a central fact table that has quantitative elements like price surrounded by dimensional tables that have descriptive attributes like location and commodity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Python Environment and Database Configuration&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.Setup Python Virtual Environment&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create a virtual environment and install necessary libraries.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python -m venv venv
source venv/bin/activate # For macOS/Linux
# .\venv\Scripts\activate # For Windows

# Create a requirements.txt file
touch requirements.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the following to requirements.txt:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pandas
SQLAlchemy
psycopg2-binary
python-dotenv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install -r requirements.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2.Create the Database and Tables&lt;/strong&gt;&lt;br&gt;
In your PostgreSQL instance, create a database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE DATABASE kenya_food_prices;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Connect to the created database and use this SQL script to set up a star schema.&lt;br&gt;
UNIQUE constraints in the SQL scripts are key to prevent duplicating dimension data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE TABLE dim_date (
    date_id SERIAL PRIMARY KEY,
    date_value DATE NOT NULL UNIQUE,
    year INTEGER NOT NULL,
    month INTEGER NOT NULL,
    day INTEGER NOT NULL
);

CREATE TABLE dim_location (
    location_id SERIAL PRIMARY KEY,
    admin1 VARCHAR(255),
    admin2 VARCHAR(255),
    market VARCHAR(255),
    UNIQUE (admin1, admin2, market)
);

CREATE TABLE dim_commodity (
    commodity_id SERIAL PRIMARY KEY,
    category VARCHAR(255),
    commodity_name VARCHAR(255),
    unit VARCHAR(255),
    UNIQUE (category, commodity_name, unit)
);

CREATE TABLE dim_market_type (
    market_type_id SERIAL PRIMARY KEY,
    market_type VARCHAR(255) UNIQUE
);

CREATE TABLE fact_food_prices (
    price_id SERIAL PRIMARY KEY,
    date_id INTEGER REFERENCES dim_date(date_id),
    location_id INTEGER REFERENCES dim_location(location_id),
    commodity_id INTEGER REFERENCES dim_commodity(commodity_id),
    market_type_id INTEGER REFERENCES dim_market_type(market_type_id),
    price_kes NUMERIC(10, 2),
    price_usd NUMERIC(10, 2),
    UNIQUE (date_id, location_id, commodity_id, market_type_id)
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3.Storing Credentials Securely&lt;/strong&gt;&lt;br&gt;
Create a .env file in project root to safely store credentials.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DB_HOST=localhost
DB_NAME=kenya_food_prices
DB_USER=your_postgres_user
DB_PASSWORD=your_postgres_password
DB_PORT=5432
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will use &lt;strong&gt;python-dotenv&lt;/strong&gt; to load the credentials securely in our python script.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Python ETL Script&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Part 1: Extraction and Transformation&lt;/strong&gt;&lt;br&gt;
First we use Pandas to read and extract the csv.&lt;br&gt;
The CSV file has an extra header row we need to skip and messy column names.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import pandas as pd
import os
from dotenv import load_dotenv
from sqlalchemy import create_engine

# Load environment variables
load_dotenv()
db_host = os.getenv("DB_HOST")
# ... (load other db variables)
conn_string = f'postgresql://{db_user}:{db_password}@{db_host}/{db_name}'
engine = create_engine(conn_string)

def extraction_and_transformation():
    # Extraction: Read CSV, skipping the second row which is a comment
    df = pd.read_csv('wfp_food_prices_ken.csv', skiprows=[1])

    # Transformation
    df = df.dropna()
    df.columns = df.columns.str.strip() # Clean column names
    df.drop_duplicates(inplace=True)
    df.reset_index(drop=True, inplace=True)

    print("Data extracted and transformed successfully!")
    return df
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Part 2: Populating the Database&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We make our script idempotent- this means it can run multiple times without creating duplicate data.&lt;/p&gt;

&lt;p&gt;We'll start with the &lt;strong&gt;location&lt;/strong&gt; dimension:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def load_location_dimension(df):
    print("Loading location dimension...")

    # 1. Select unique locations from the source data
    location_cols = ['admin1', 'admin2', 'market']
    locations = df[location_cols].drop_duplicates()

    # 2. Get existing locations from the database
    existing = pd.read_sql("SELECT admin1, admin2, market FROM dim_location", engine)

    # 3. Find locations that are in our source but NOT in the database
    new_locations = locations.merge(existing, on=location_cols, how='left', indicator=True)
    new_locations = new_locations[new_locations['_merge'] == 'left_only'].drop('_merge', axis=1)

    # 4. If there are new locations, append them
    if not new_locations.empty:
        new_locations.to_sql('dim_location', engine, if_exists='append', index=False)
        print(f"Inserted {len(new_locations)} new location records!")
    else:
        print("✔️ No new location records to add.")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Use the same logic for the other dimensions!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Loading the Fact Table&lt;/strong&gt;&lt;br&gt;
We replace the descriptive text (e.g.,Beans, Nairobi) with corresponding foreign keys(location_id, commodity_id) from our dimension tables.&lt;/p&gt;

&lt;p&gt;We manage to do this via a series of pd.merge calls, this is Pandas equivalent to SQL JOIN.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def load_fact_table(df):
    print("Loading fact table...")

    # Get dimension tables from the DB, now with their generated IDs
    date_dim = pd.read_sql("SELECT date_id, date_value FROM dim_date", engine)
    location_dim = pd.read_sql("SELECT location_id, admin1, admin2, market FROM dim_location", engine)
    commodity_dim = pd.read_sql("SELECT commodity_id, category, commodity_name, unit FROM dim_commodity", engine)
    # ... and so on for other dimensions

    # Prep the dataframe for merging
    fact_df = df.rename(columns={'commodity': 'commodity_name', 'price': 'price_kes'})
    fact_df['date_value'] = pd.to_datetime(df['date']).dt.date

    # Merge with dimensions to get foreign keys
    fact_df = fact_df.merge(date_dim, on='date_value', how='left')
    fact_df = fact_df.merge(location_dim, on=['admin1', 'admin2', 'market'], how='left')
    fact_df = fact_df.merge(commodity_dim, on=['category', 'commodity_name', 'unit'], how='left')
    # ... merge with other dimensions

    # Select only the columns we need for the fact table
    fact_columns = ['date_id', 'location_id', 'commodity_id', 'market_type_id', 'price_kes', 'price_usd']
    fact_table = fact_df[fact_columns].dropna() # Drop rows where a join failed

    # Load into the database (with a similar idempotency check)
    fact_table.to_sql('fact_food_prices', engine, if_exists='append', index=False)

    print("Fact table loaded successfully!")

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3: Visualizing Data with Grafana&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After cleaning and structuring our data it is now ready for Grafana.&lt;br&gt;
1.&lt;strong&gt;Connect PostgreSQL to Grafana&lt;/strong&gt;:In Grafana, go to Connections &amp;gt; Add new connection, select PostgreSQL, and enter your database credentials.&lt;/p&gt;

&lt;p&gt;2.Create a New Dashboard: Add a panel and switch to code editor and enter SQL queries.&lt;/p&gt;

&lt;p&gt;Here are some queries to get you started.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Query 1: Price of a Commodity Over Time&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Panel Type: Time Series&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT
  d.date_value AS "time",      -- Alias for Grafana's time axis
  f.price_kes,                 -- The value to plot
  c.commodity_name AS "metric" -- The name of the series
FROM
  fact_food_prices AS f
JOIN
  dim_date AS d ON f.date_id = d.date_id
JOIN
  dim_commodity AS c ON f.commodity_id = c.commodity_id
JOIN
  dim_location AS l ON f.location_id = l.location_id
WHERE
  $__timeFilter(d.date_value) AND -- Use Grafana's time picker
  l.market = 'Nairobi' AND
  c.commodity_name = 'Maize (white)'
ORDER BY
  d.date_value;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Query 2: Average Price Comparison by Commodity&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Panel Type: Bar Chart&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT
  c.commodity_name AS "Commodity",
  AVG(f.price_kes) AS "Average Price (KES)"
FROM
  fact_food_prices AS f
JOIN
  dim_commodity AS c ON f.commodity_id = c.commodity_id
JOIN
  dim_date AS d ON f.date_id = d.date_id
WHERE
  $__timeFilter(d.date_value)
GROUP BY
  c.commodity_name
ORDER BY
  "Average Price (KES)" DESC
LIMIT 15;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We've taken raw data, applied ETL principles, modeled it for analytics, and built a interactive dashboard.&lt;/p&gt;

</description>
      <category>dataengineering</category>
      <category>programming</category>
      <category>python</category>
    </item>
    <item>
      <title>Building a Gold (XAUUSD) Trend Tracker with Python and SQLite</title>
      <dc:creator>Austin Oketch</dc:creator>
      <pubDate>Mon, 19 May 2025 22:25:01 +0000</pubDate>
      <link>https://dev.to/austin_oketch/building-a-gold-xauusd-trend-tracker-with-python-and-sqlite-3l95</link>
      <guid>https://dev.to/austin_oketch/building-a-gold-xauusd-trend-tracker-with-python-and-sqlite-3l95</guid>
      <description>&lt;p&gt;&lt;strong&gt;XAUUSD&lt;/strong&gt; is a symbol used in Forex trading to indicate the number of US dollars needed to buy one ounce of gold.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Other abbreviations such as &lt;strong&gt;EURUSD&lt;/strong&gt; indicate the exchange rate of national currency pairs while &lt;strong&gt;XAUUSD&lt;/strong&gt; shows comparison between the price of the precious metal and the rate of the US dollar.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It is possible to buy gold as a physical commodity at banks or from dealers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Gold is often used by governments that have a large gold reserve to protect the value of their currency; that’s why it is traded on the Forex market.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I chose XAUUSD due to high volume of trading together with an extensive amount of historical and real-time data available.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It is also not specific to any one nation, economy, or business; rather, it is globally essential.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It is more intriguing examining how the price of gold responds to an array of events, including inflation, interest rates, wars, and financial crises.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Objectives
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;When I was implementing this project what I had in mind was a simple Extraction,Transformation and Load pipeline.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I am using &lt;a href="https://twelvedata.com" rel="noopener noreferrer"&gt;TwelveData&lt;/a&gt; forex API for &lt;strong&gt;Extraction&lt;/strong&gt; of raw data from the financial markets in JSON format.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After &lt;strong&gt;Extraction&lt;/strong&gt; we now begin the &lt;strong&gt;Transformation&lt;/strong&gt; of the raw data.This is done to get insight providing a clean dataset for analysis and alerts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Finally &lt;strong&gt;Loading&lt;/strong&gt; of the data involves the storage of the transformed dataset into a database for presentation or more processing purposes.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step by Step Build:
&lt;/h2&gt;

&lt;p&gt;Get an API_KEY after setting up an account in &lt;a href="https://twelvedata.com/" rel="noopener noreferrer"&gt;TwelveData&lt;/a&gt;, don't worry there is a free plan option.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;.gitignore file:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;.env file:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;API_KEY='xxxxxxxxxxxxxxxxxxxxxx'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Add the API_KEY to your .env file - &lt;strong&gt;remember to add the .env file in your .gitignore file.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A &lt;strong&gt;.gitignore&lt;/strong&gt; file specifies intentionally untracked files that Git should ignore.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In case you are using version control, this will prevent the pushing of the sensitive API_KEY to GitHub. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;extract.py:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here, extraction of the raw data took place via an API.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import requests
import os
from dotenv import load_dotenv

load_dotenv()

GOLD_API_KEY = os.getenv('API_KEY')

def fetch_xauusd_data():
    url = f"https://api.twelvedata.com/time_series?symbol=XAU/USD&amp;amp;interval=5min&amp;amp;apikey={GOLD_API_KEY}"
    return requests.get(url).json()

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import requests
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Requests is a python HTTP library.It is commonly used for interacting with web services, APIs and web scraping.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In this context we are using it to send GET requests to retrieve data.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import os
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The OS module provides functions used to interact with operating system. The module here is used to work with files and directories.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from dotenv import load_dotenv
load_dotenv()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;These lines of code import load_dotenv function from dotenv library.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It loads environmental variables present in the .env file.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GOLD_API_KEY = os.getenv('API_KEY')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;This assigns the value of the environmental variable "API_KEY" to the variable GOLD_API_KEY.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def fetch_xauusd_data():
    url = f"https://api.twelvedata.com/time_series?symbol=XAU/USD&amp;amp;interval=5min&amp;amp;apikey={GOLD_API_KEY}"
    return requests.get(url).json()

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;This function connects to a service that provides financial data, TwelveData API.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It is requesting five-minute intervals of XAUUSD commodity data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The request is authenticated by the API_KEY stored in the GOLD_API_KEY variable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The response is given back in JSON format with a similar structure to a Python dictionary.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;transform.py:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def transform_data(df):
    df['close'] = df['close'].astype(float)
    df['SMA1O'] = df['close'].rolling(window=10).mean()
    df['candle'] = df.apply(lambda row: 'Bullish' if row['close'] &amp;lt; row['SMA1O'] else 'Bearish', axis=1)
    return df
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;df['close'] = df['close'].astype(float)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The API sends the data as string text.&lt;/li&gt;
&lt;li&gt;This line of code converts the 'close' column in the response to float.&lt;/li&gt;
&lt;li&gt;This will enable one to perform calculations like averages on the data in the column.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;df['SMA1O'] = df['close'].rolling(window=10).mean()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;This line creates a new column called 'SMA1O'&lt;/li&gt;
&lt;li&gt;It computes the average of the last 10 'close' prices for every row.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;df['candle'] = df.apply(lambda row: 'Bullish' if row['close'] &amp;lt; row['SMA1O'] else 'Bearish', axis=1)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;This line adds a new column called 'candle' that labels the market condition based on a simple trend rule:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If the closing price is above the 10-period moving average (SMA10) → label it 'Bullish'.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If the closing price is below the SMA10 → label it 'Bearish'.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;load.py:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import sqlite3

def load_data(df, db_name='xauusd_data.db'):
    conn = sqlite3.connect(db_name)
    df.to_sql('xauusd_prices',conn, if_exists='append', index=False)
    conn.close()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import sqlite3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;SQLite is a C-language library that implements a small, fast, self-contained, high-reliability, full-featured, SQL database engine.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def load_data(df, db_name='xauusd_data.db'):
    conn = sqlite3.connect(db_name)
    df.to_sql('xauusd_prices',conn, if_exists='append', index=False)
    conn.close()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The load_data function takes two inputs, the transformed DataFrame,df and optional name of sqlite3 database file.&lt;/li&gt;
&lt;li&gt;After connecting to the SQLite file the DataFrame is saved to the table.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;if_exists='append'&lt;/code&gt; - means new rows will be added to the table not overwrite it.&lt;br&gt;
&lt;code&gt;index='False'&lt;/code&gt;- don't include Index column in the DataFrame.&lt;/p&gt;

&lt;p&gt;Now to combine these scripts into one - *&lt;em&gt;main.py *&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from extract import fetch_xauusd_data
from transform import transform_data
from load import load_data
import pandas as pd

def run_etl():
    print("Starting ETL pipeline...")


    print("Starting data extraction...")
    raw_data = fetch_xauusd_data()

    if 'values' not in raw_data:
        print("No data found, Check api configuration or usage!")
        return


    print("Starting data transformation...")
    df = pd.DataFrame(raw_data['values'])
    df = transform_data(df)


    print("Starting data loading...")
    load_data(df)

    print("ETL pipeline finished successfully!")

if __name__ == "__main__":
    run_etl()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;I combined all of this into a single main.py file. The entire ETL pipeline is coordinated by:&lt;/li&gt;
&lt;li&gt;Retrieving pricing information for gold (XAU/USD) via an API&lt;/li&gt;
&lt;li&gt;Converting it to label candles and compute moving averages using Pandas&lt;/li&gt;
&lt;li&gt;The output is saved in a SQLite database.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>dataengineering</category>
      <category>programming</category>
      <category>python</category>
    </item>
    <item>
      <title>Introduction to Python Programming Language</title>
      <dc:creator>Austin Oketch</dc:creator>
      <pubDate>Wed, 16 Apr 2025 09:37:40 +0000</pubDate>
      <link>https://dev.to/austin_oketch/introduction-to-python-programming-language-5a6e</link>
      <guid>https://dev.to/austin_oketch/introduction-to-python-programming-language-5a6e</guid>
      <description>&lt;p&gt;Python's popularity as a programming language has steadily increased over the years since its introduction in 1991 by Guido van Rossum. Python is quite popular due to its easy-to-read nature.This can be seen with the indentation blocks that make the code to be visually appealing for easy understanding by collaborators on a project.A beginner can easily understand the code with minimal programming experience.Another reason is due to its versatility as it provides utility in most software engineering use cases ranging from software development to machine learning.&lt;/p&gt;

&lt;h2&gt;
  
  
  Python use cases
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;These are some of the applications of python in the world of software engineering:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;a) &lt;strong&gt;Data Analysis and Science&lt;/strong&gt;.This includes data cleaning and manipulation, Statistical analysis and Data Visualization.&lt;/p&gt;

&lt;p&gt;b) &lt;strong&gt;Software Development&lt;/strong&gt;.Python together with frameworks like Flask and Django can be used in the development of web applications.&lt;/p&gt;

&lt;p&gt;c) &lt;strong&gt;Scripting and Automation&lt;/strong&gt;.Python can also be used in writing scripts that automate tasks eg for software testing and data processing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Python compared to other programming languages
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Python usually uses new lines to complete a command. Other programming languages like JavaScript use semi-colons.&lt;/li&gt;
&lt;li&gt;Python is more flexible compared to the other programming languages as it can be used in a Procedural, Function or Object-oriented programming way.&lt;/li&gt;
&lt;li&gt;Python was designed with readability in mind hence easier to understand code compared to the other programming languages.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Getting started with Python&lt;/strong&gt;&lt;br&gt;
The python version that is mainly being used currently is python 3.&lt;/p&gt;

&lt;p&gt;Most Windows,Mac and Linux systems nowadays come with Python installed.&lt;/p&gt;

&lt;p&gt;To check if you have Python installed in your Windows PC open the command-line application(cmd.exe) and enter the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C:\Users\username&amp;gt;python --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For MacOS or Linux systems open terminal/console and enter the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If python is not installed in your PC then you can download it from &lt;br&gt;
&lt;a href="https://www.python.org/" rel="noopener noreferrer"&gt;https://www.python.org/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want to access the python command line, enter the following command in the terminal of your system:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# username @ test_computer in ~ [20:27:34] 
$ python3
Python 3.11.2 (main, Nov 30 2024, 21:22:50) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
&amp;gt;&amp;gt;&amp;gt; 

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here you can directly write syntax and execute python commands.&lt;/p&gt;

&lt;p&gt;Programmers use code editors eg Visual Studio Code and Intergrated Development Environment(IDE) like Pycharm for software development and production.&lt;/p&gt;

&lt;h2&gt;
  
  
  Python Syntax Examples
&lt;/h2&gt;

&lt;p&gt;Python syntax is usually given a nickname, "executable pseudo code".&lt;br&gt;
An example will explain why:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print("Hello world")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This piece of code will do exactly what you think it will, give output "Hello world" in the console.&lt;/p&gt;

&lt;p&gt;.py format is the standard for writing and executing python programs.&lt;/p&gt;

&lt;p&gt;If you want to run Python program in terminal enter the following command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python3 app.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Variables
&lt;/h2&gt;

&lt;p&gt;Variables are containers for storing data values.In python a variable is created the moment you first assign a value to it.They also do not need to be declared with a certain type, the type can even change after being set.&lt;br&gt;
Variables can store data of different types, and different types can do different things.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;age = 5 # age is of type int
age = 'five' # age is now a str
print(age) # output will now be five
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Rules for Python variables:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A variable name must start with a letter or the underscore character&lt;/li&gt;
&lt;li&gt;A variable name cannot start with a number&lt;/li&gt;
&lt;li&gt;A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )&lt;/li&gt;
&lt;li&gt;Variable names are case-sensitive (age, Age and AGE are three different variables)&lt;/li&gt;
&lt;li&gt;A variable name cannot be any of the Python keywords.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Python has the following data types:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Text type: String&lt;/strong&gt;&lt;br&gt;
Strings are used to store text data and are immutable(cannot be changed after they are created)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name = "Kamau"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Numeric Types: int, float&lt;/strong&gt;&lt;br&gt;
Int are whole numbers without a decimal point while float have a decimal point&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;buying_price = 250
vat = 45.60

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Sequence Types: list, tuple, range&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Lists are mutable, allowing you to modify their content, while tuples are immutable, meaning you can’t change them after creation.&lt;br&gt;
Range consists of a sequence of data values often used in loops.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fruits = ["apple", "banana", "cherry"]  # list
coordinates = (10, 20)                  # tuple
for i in range(3):
    print(fruits[i])                   # prints each fruit

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Mapping Type: dict&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Dictionaries are used to store values in key value pairs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;person = {"name": "Alice", "age": 30}
print(person["name"])  # Outputs: Alice

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Set Types: set&lt;/strong&gt;&lt;br&gt;
Sets are used to store multiple items in a single variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;unique_numbers = {1, 2, 3, 3, 2}
print(unique_numbers)  # Outputs: {1, 2, 3}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Boolean Type: bool&lt;/strong&gt;&lt;br&gt;
Boolean represents one of two values: True or False&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;is_sunny = True
if is_sunny:
    print("Wear sunglasses!")  # Will print

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Python Operators
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Arithmetic Operators&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Arithmetic operators are used with numeric values to perform common mathematical operations:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;+    Addition    (x + y) &lt;/li&gt;
&lt;li&gt;-    Subtraction (x - y) &lt;/li&gt;
&lt;li&gt;*    Multiplication  (x * y) &lt;/li&gt;
&lt;li&gt;/    Division    (x / y) &lt;/li&gt;
&lt;li&gt;%    Modulus         (x % y) &lt;/li&gt;
&lt;li&gt;**   Exponentiation  (x ** y)
&lt;/li&gt;
&lt;li&gt;//   Floor division  (x // y)
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print(20+2) # answer = 22
print(20-2) # answer = 18
print(8*6) # answer = 48
print(18/2) # answer = 9
print(2 ** 6)  # answer is 64 (exponent)
print(17 % 2)  # answer is 1 (remainder)
print(11 // 2)  # 5 (floor division)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Logical, Comparison and Conditional operators&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Comparison operators check relationships between values:&lt;/strong&gt;&lt;br&gt;
== (equal to)&lt;br&gt;
!= (not equal to)&lt;br&gt;
&amp;lt; (less than)&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;(greater than)&lt;br&gt;
&amp;lt;= (less than or equal to)&lt;br&gt;
= (greater than or equal to)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Logical operators to combine conditions:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;and (both conditions must be true)&lt;br&gt;
or (at least one condition must be true)&lt;br&gt;
not (inverts a boolean value)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conditional statements to make decisions:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;if (executes code if condition is true)&lt;br&gt;
elif (checks another condition if previous conditions were false)&lt;br&gt;
else (executes if all previous conditions were false)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;temperature = 25  # in Celsius

# Comparison operators
is_freezing = temperature &amp;lt;= 0
is_hot = temperature &amp;gt;= 30
is_warm = temperature &amp;gt; 20

# Logical operators
wear_jacket = is_freezing or (temperature &amp;lt; 15)
go_swimming = is_hot and not is_freezing

# Conditional statements
if is_freezing:
    print("It's freezing! Wear a heavy coat.")
elif is_hot:
    print("It's hot! Consider wearing light clothes.")
else:
    print("The temperature is moderate.")

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conditional statements - Loops
&lt;/h2&gt;

&lt;p&gt;Conditional statements are used to execute a block of code multiple times until certain conditions are met.&lt;br&gt;
This reduces code duplication making code more readable.&lt;/p&gt;

&lt;p&gt;Types of loops in python&lt;br&gt;
For loop&lt;br&gt;
While loop&lt;/p&gt;

&lt;p&gt;Python is a great beginner friendly general programming language to start your journey in the world of software development due to its easy to read and understand nature.Patience and some programming fundamentals is all you require.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>python</category>
      <category>productivity</category>
      <category>learning</category>
    </item>
  </channel>
</rss>
