Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save carloocchiena/ebab556d90630817e7c88cf92daf50e0 to your computer and use it in GitHub Desktop.
Save carloocchiena/ebab556d90630817e7c88cf92daf50e0 to your computer and use it in GitHub Desktop.
# --- 1. Libraries ---
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from datetime import timedelta
# --- 2. Load the Excel file ---
# Replace with your actual filename
df = pd.read_excel('20240101_20241231_sample.xlsx')
# --- 3. Rename and parse columns ---
df.columns = ['Date', 'Time', 'Value']
# Convert 'Data' to datetime
df['Date'] = pd.to_datetime(df['Date'], dayfirst=True)
# Convert 'Ora' from 1–24 to 0–23 (Python datetime uses 0–23)
df['Time'] = df['Time'] - 1
# Create a full timestamp
df['Timestamp'] = df['Date'] + pd.to_timedelta(df['Time'], unit='h')
df.set_index('Timestamp', inplace=True)
# --- 4. Convert 'Prezzo' to float ---
# Handle comma as decimal separator
df['Value'] = df['Value'].astype(str).str.replace(',', '.').astype(float)
# --- 5. Preview the data ---
print(df.head())
# --- 6. Descriptive statistics ---
print(df['Value'].describe())
# --- 7. Time series plot ---
plt.figure(figsize=(16, 5))
plt.plot(df.index, df['Value'], linewidth=0.5)
plt.title('Andamento time series', fontsize=14)
plt.xlabel('Date')
plt.ylabel('Value')
plt.grid(True)
plt.tight_layout()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment