1

I have sales data from Jan 2014 until last week and data will refresh everyday.

I want to generate some insights automatically to compare to the latest week, for example how much sales decreased/increased from last week to this week and which is the hot product etc.

I am confused with how to store latest week dynamically

 import pandas as pd
 import numpy as np

 df = pd.DataFrame({
     'Product': ['EyeWear', 'Packs', 'Watches', 'Irons', 'Glasses'],
     'Country':['USA','India','Africa','UK','India'],
     'Revenue':[98,90,87,69,78],
     'Date':['20140101','20140102','20140103','20140104','20140105']},
     index=[1,2,3,4,5])

    df['Date'] = pd.to_datetime(df['Date'], errors='coerce')

    df['year'] = df['Date'].dt.year 
    df['month'] = df['Date'].dt.month
    df['week'] = df['Date'].dt.week 
    df['YearMonth'] = df['Date'].apply(lambda x:x.strftime('%Y%m')) 
Diego Aguado
  • 1,604
  • 18
  • 36
Kumar AK
  • 987
  • 3
  • 10
  • 23
  • You can create an SQLite database having a different table for each week and keep updating these table every day and then access them from pandas using read_sql method. I hope this helps – Sahil Dahiya Dec 22 '17 at 20:12
  • This thread might be helpful: https://stackoverflow.com/questions/17098654/how-to-store-a-dataframe-using-pandas – Drza loren Dec 23 '17 at 21:44

0 Answers0