import pandas as pd
import pyscd

"""
Explanation: Getting started
In this section, we will see how to use PySCD to track history changes in pandas DataFrame objects. For more detailed information about Slowly Changing Dimensions, you can check this page on Wikipedia.
Importing packages
Befor starting you need to import the public objects os pandas and pyscd packages. You do that by executing:
End of explanation
"""


df = pd.read_csv('clients 2015-01.csv')
df

"""
Explanation: Creating a dimension from scratch
Use one of the pandas IO tools to read your data (from CSV, HDF5, ...)
End of explanation
"""


dim = pyscd.SlowlyChangingDimension(
    df, source_keys='ssn', as_of='2015-01-01')
dim.df

"""
Explanation: Now, lets create a dimension from this dataframe:
End of explanation
"""


df = pd.read_csv('clients 2015-02.csv')
df

"""
Explanation: I used the as_of parameter here to indicate that this data from January. When as_of is ommited, the dimension will always use the current date.
Updating dimension with new data
Now lets import a new clients table:
End of explanation
"""


dim.as_of = '2015-02-01'

dim.update(df)

dim.df

"""
Explanation: Note that Fred has moved from FL to NY.
Before updating the dimension with this new data, lets indicate that this time the data is from February.
End of explanation
"""


