<?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: gerald mutuku</title>
    <description>The latest articles on DEV Community by gerald mutuku (@gerald_mutuku_92f7710cf31).</description>
    <link>https://dev.to/gerald_mutuku_92f7710cf31</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%2F2148102%2F4543207d-8668-468d-b748-8e8c6947d3b1.jpg</url>
      <title>DEV Community: gerald mutuku</title>
      <link>https://dev.to/gerald_mutuku_92f7710cf31</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gerald_mutuku_92f7710cf31"/>
    <language>en</language>
    <item>
      <title>Using python in real time data weather analysis</title>
      <dc:creator>gerald mutuku</dc:creator>
      <pubDate>Sat, 26 Oct 2024 15:12:53 +0000</pubDate>
      <link>https://dev.to/gerald_mutuku_92f7710cf31/using-python-in-real-time-data-weather-analysis-dep</link>
      <guid>https://dev.to/gerald_mutuku_92f7710cf31/using-python-in-real-time-data-weather-analysis-dep</guid>
      <description>&lt;p&gt;This guide outlines the steps to set up a Python-based system for collecting, storing, and analyzing real-time weather data. We’ll pull data from a weather API, store it in a structured format, and visualize trends, making this an adaptable solution for fields impacted by weather, such as agriculture, tourism, and event planning.&lt;br&gt;
Step 1: Import Libraries&lt;/p&gt;

&lt;p&gt;We’ll begin by importing essential libraries for data collection, storage, scheduling, and visualization:&lt;/p&gt;

&lt;p&gt;python&lt;/p&gt;

&lt;p&gt;import requests          # For API data retrieval&lt;br&gt;
import pandas as pd      # For data storage and manipulation&lt;br&gt;
import time              # For scheduling data retrieval&lt;br&gt;
import matplotlib.pyplot as plt  # For data visualization&lt;br&gt;
from datetime import datetime    # For timestamping each data entry&lt;/p&gt;

&lt;p&gt;Step 2: Configure the Weather API&lt;/p&gt;

&lt;p&gt;Set up the connection to the weather API. This example uses weatherapi.com, but it can be adapted to other weather APIs by updating the endpoint and request parameters.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;API Key: Replace 'your_api_key' with your API key from the provider.
City: Adjust the city variable to monitor different locations.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;python&lt;/p&gt;

&lt;p&gt;api_key = 'your_api_key'&lt;br&gt;
city = 'Nairobi'&lt;br&gt;
url = f"&lt;a href="http://api.weatherapi.com/v1/current.json?key=%7Bapi_key%7D&amp;amp;q=%7Bcity%7D&amp;amp;aqi=no" rel="noopener noreferrer"&gt;http://api.weatherapi.com/v1/current.json?key={api_key}&amp;amp;q={city}&amp;amp;aqi=no&lt;/a&gt;"&lt;/p&gt;

&lt;p&gt;Step 3: Function for Data Retrieval&lt;/p&gt;

&lt;p&gt;This function queries the API, extracts the weather information, and structures it into a dictionary. Each query returns the city name, temperature, humidity, wind speed, and a timestamp.&lt;/p&gt;

&lt;p&gt;python&lt;/p&gt;

&lt;p&gt;def fetch_weather_data():&lt;br&gt;
    response = requests.get(url)&lt;br&gt;
    data = response.json()&lt;br&gt;
    weather_info = {&lt;br&gt;
        'city': data['location']['name'],&lt;br&gt;
        'temperature': data['current']['temp_c'],&lt;br&gt;
        'humidity': data['current']['humidity'],&lt;br&gt;
        'wind_speed': data['current']['wind_kph'],&lt;br&gt;
        'timestamp': datetime.now()&lt;br&gt;
    }&lt;br&gt;
    return weather_info&lt;/p&gt;

&lt;p&gt;Step 4: Automate Data Collection&lt;/p&gt;

&lt;p&gt;Using a while loop, the script repeatedly fetches data every 10 minutes (600 seconds) and appends it to a DataFrame. The script will run continuously, logging new data with each interval.&lt;/p&gt;

&lt;p&gt;python&lt;/p&gt;

&lt;p&gt;weather_data = pd.DataFrame(columns=['city', 'temperature', 'humidity', 'wind_speed', 'timestamp'])&lt;/p&gt;

&lt;p&gt;try:&lt;br&gt;
    while True:&lt;br&gt;
        # Fetch and append new data to the DataFrame&lt;br&gt;
        new_data = fetch_weather_data()&lt;br&gt;
        weather_data = weather_data.append(new_data, ignore_index=True)&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    # Display the latest data entries
    print(weather_data.tail())

    # Wait for the next data retrieval interval (10 minutes)
    time.sleep(600)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;except KeyboardInterrupt:&lt;br&gt;
    print("Data collection stopped.")&lt;/p&gt;

&lt;p&gt;Step 5: Data Visualization&lt;/p&gt;

&lt;p&gt;The following function generates a line plot displaying temperature, humidity, and wind speed changes over time. This step provides a visual representation of weather patterns.&lt;/p&gt;

&lt;p&gt;python&lt;/p&gt;

&lt;p&gt;import matplotlib.dates as mdates&lt;/p&gt;

&lt;p&gt;def plot_weather_data(df):&lt;br&gt;
    plt.figure(figsize=(10, 5))&lt;br&gt;
    plt.plot(df['timestamp'], df['temperature'], label='Temperature (°C)')&lt;br&gt;
    plt.plot(df['timestamp'], df['humidity'], label='Humidity (%)')&lt;br&gt;
    plt.plot(df['timestamp'], df['wind_speed'], label='Wind Speed (kph)')&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Format x-axis for timestamp readability&lt;br&gt;
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d %H:%M'))&lt;br&gt;
plt.gca().xaxis.set_major_locator(mdates.HourLocator(interval=1))&lt;br&gt;
plt.gcf().autofmt_xdate()

&lt;p&gt;plt.title(f'Real-time Weather Data for {city}')&lt;br&gt;
plt.xlabel('Time')&lt;br&gt;
plt.ylabel('Measurements')&lt;br&gt;
plt.legend()&lt;br&gt;
plt.show()&lt;br&gt;
&lt;/p&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h1&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Call this plot function every 30 minutes for updates&lt;br&gt;
&lt;/h1&gt;

&lt;p&gt;while True:&lt;br&gt;
    plot_weather_data(weather_data)&lt;br&gt;
    time.sleep(1800)&lt;/p&gt;

&lt;p&gt;Step 6: Data Storage for Historical Analysis&lt;/p&gt;

&lt;p&gt;To store collected data, export it to a CSV file. This allows for historical weather analysis and trend evaluation.&lt;/p&gt;

&lt;p&gt;python&lt;/p&gt;

&lt;h1&gt;
  
  
  Save data to a CSV file for long-term storage and analysis
&lt;/h1&gt;

&lt;p&gt;weather_data.to_csv('weather_data.csv', index=False)&lt;/p&gt;

&lt;p&gt;Optional: Setting Up Forecasting Capabilities&lt;/p&gt;

&lt;p&gt;With an extensive dataset over days or weeks, consider implementing predictive models like ARIMA or Facebook’s Prophet to identify weather trends or create forecasts. This would involve additional libraries and configuration but can significantly enhance the project’s utility.&lt;/p&gt;

&lt;p&gt;This setup provides a foundational framework for real-time weather monitoring and analysis, with opportunities for further customization to suit domain-specific requirements.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Python 101: Introduction to Python as a Data Analytics Tool</title>
      <dc:creator>gerald mutuku</dc:creator>
      <pubDate>Sun, 06 Oct 2024 14:00:59 +0000</pubDate>
      <link>https://dev.to/gerald_mutuku_92f7710cf31/python-101-introduction-to-python-as-a-data-analytics-tool-4mmk</link>
      <guid>https://dev.to/gerald_mutuku_92f7710cf31/python-101-introduction-to-python-as-a-data-analytics-tool-4mmk</guid>
      <description>&lt;p&gt;Python has become a go-to tool in data analytics for a good reason—it's both powerful and easy to learn. If you’re just stepping into this field, Python makes your life easier by being straightforward and versatile. Its clean, readable syntax lets you focus on the fun part—working with data—rather than getting bogged down in complicated code. Imagine you have a messy dataset from a spreadsheet, full of missing values and inconsistent formats. With Python’s Pandas library, you can clean that data in minutes, and suddenly, you’re ready to dive in and analyze it.&lt;/p&gt;

&lt;p&gt;Python’s ecosystem is like a toolkit, packed with everything you need. NumPy helps with numbers and arrays, Matplotlib and Seaborn turn raw data into beautiful charts, and libraries like Scikit-learn even let you explore machine learning when you're ready to take it up a notch. The best part? You can start small, like generating a quick summary of sales data, and soon, you’ll be creating detailed visualizations and statistical models.&lt;/p&gt;

&lt;p&gt;As you go through the process—collecting, cleaning, analyzing, and visualizing data—you’ll realize that Python isn’t just a tool, it’s a game-changer. It takes the tedious parts of data analysis and streamlines them, leaving you more time to uncover insights and tell stories with your data. And while learning any new skill can feel a little overwhelming at first, Python’s large community and wealth of tutorials mean that help is always just a search away. Before you know it, Python will feel like second nature, a trusty companion that makes even the toughest data challenges manageable.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>SQL 101: Introduction to Structured Query Language.</title>
      <dc:creator>gerald mutuku</dc:creator>
      <pubDate>Mon, 30 Sep 2024 17:14:37 +0000</pubDate>
      <link>https://dev.to/gerald_mutuku_92f7710cf31/sql-101-introduction-to-structured-query-language-26ae</link>
      <guid>https://dev.to/gerald_mutuku_92f7710cf31/sql-101-introduction-to-structured-query-language-26ae</guid>
      <description>&lt;p&gt;SQL (Structured Query Language) is the standard language for managing relational databases. It allows you to query, update, and manage data. SQL is essential for anyone working with data, whether in analysis, development, or database administration.&lt;br&gt;
SQL is a crucial skill for handling data. With it, you can query, manipulate, and manage databases effectively. Keep practicing to master more complex queries and database operations.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
