Tips and tricks when working with datasets

Financial Forecasting in Python

Victoria Clark

CGMA Financial Analyst

Common challenges when working with financial data

  • Raw data is in different formats
  • Date format can be different!

    • US format is Month-Day-Year, EU is Day-Month-Year
    • 09-08-2018 in US is the 8th of September, EU is 9th of August
  • Can cause challenges in:

    • Interpreting
    • Combining
Financial Forecasting in Python

Using a dictionary

  • Dictionary: associative array
  • Keys are mapped to values
  • un-ordered key-value-pairs

  • For example:

    • The value 01 has a key of Jan
dictionary = {01: 'Jan'}

dictionary

Financial Forecasting in Python

Remember to use the datetime library

Directive Meaning Example
%d Day of the month as a zero-padded decimal number 01, 02, …, 31
%b Month as locale’s abbreviated name Jan, Feb, …, Dec
%B Month as locale’s full name January, …,
%m Month as a zero-padded decimal number 01, 02, …, 12
%y Year without century as a zero-padded decimal number 00, 01, …, 99
%Y Year with century as a decimal number 1988, 2001, 2013
# Example: 19-02-2018 will be written:
('19-02-2018', '%d-%m-%Y')
Financial Forecasting in Python

Iterate over items

  • iteritems() function
# Create dictionary with strings as keys
# and ints as values
wordFrequency = {
    "Hello" : 7,
    "hi" : 10,
    "there" : 45,
    "at" : 23,
    "this" : 77
    }
# Iterate over dictionary using for loop
for key in wordFrequency:
    value = wordFrequency[key]
    print(key, " :: ", value)
Hello  ::  7
there  ::  45
at  ::  23
this  ::  77
hi  ::  10
Financial Forecasting in Python

Let's practice!

Financial Forecasting in Python

Preparing Video For Download...