Functions
allpot.get_data Namespace Reference

Functions

def get_data_fy (domain, key, gid, fmt, read_csv_kwargs)
 
def get_data_all (get_data_args, read_csv_kwargs)
 

Detailed Description

Module to get data and load into DataFrames.

This module contains functions to load uptime data from:
    - Google Sheets

Function Documentation

def allpot.get_data.get_data_all (   get_data_args,
  read_csv_kwargs 
)
Get a DataFrames for all FYs.

Calls get_data_fy for each FY in tern.

Args
----
    get_data_args (dict): arguments to pass to `get_data_fy`
    read_csv_kwargs (dict): keyword arguments to pass to
        `pd.read_csv`

Returns
-------
    DataFrame: containing uptime data from Google Sheets uptime
        spreadsheet for all FYs
    dict: containing DataFrames for each FY

Definition at line 41 of file get_data.py.

References allpot.get_data.get_data_fy().

41 def get_data_all(get_data_args, read_csv_kwargs):
42  """Get a DataFrames for all FYs.
43 
44  Calls get_data_fy for each FY in tern.
45 
46  Args
47  ----
48  get_data_args (dict): arguments to pass to `get_data_fy`
49  read_csv_kwargs (dict): keyword arguments to pass to
50  `pd.read_csv`
51 
52  Returns
53  -------
54  DataFrame: containing uptime data from Google Sheets uptime
55  spreadsheet for all FYs
56  dict: containing DataFrames for each FY
57 
58  """
59  # Make a dict of dfs for all FYs
60  dfs = {}
61  for year, details in get_data_args['FYs'].items():
62  dfs[year] = get_data_fy(
63  get_data_args['domain'],
64  get_data_args['key'],
65  details['gid'],
66  get_data_args['format'],
67  read_csv_kwargs)
68 
69  # Make one df for ALL!
70  df = pd.concat(dfs.values(), verify_integrity=True)
71 
72  # Return concatenated 'ALL' df and dict of dfs by FY
73  return df, dfs
74 
75 
def get_data_fy(domain, key, gid, fmt, read_csv_kwargs)
Definition: get_data.py:10
def get_data_all(get_data_args, read_csv_kwargs)
Definition: get_data.py:41
def allpot.get_data.get_data_fy (   domain,
  key,
  gid,
  fmt,
  read_csv_kwargs 
)
Get a DataFrame from Google Sheets for a single FY.

Args
----
    domain (str): 'https://docs.google.com/spreadsheets/d/' in most cases.
    key (str): key for the Google Sheets document
    gid (str): ID of the specific sheet to load data from
    fmt (str): Format in which to expect data - will be 'csv' in
        most cases
    read_csv_kwargs (dict): Additional keyword arguments to pass to
        `pd.read_csv`

Returns
-------
    DataFrame: containing data from the Google Sheets uptime
        spreadsheet

Definition at line 10 of file get_data.py.

Referenced by allpot.get_data.get_data_all().

10 def get_data_fy(domain, key, gid, fmt, read_csv_kwargs):
11  """Get a DataFrame from Google Sheets for a single FY.
12 
13  Args
14  ----
15  domain (str): 'https://docs.google.com/spreadsheets/d/' in most cases.
16  key (str): key for the Google Sheets document
17  gid (str): ID of the specific sheet to load data from
18  fmt (str): Format in which to expect data - will be 'csv' in
19  most cases
20  read_csv_kwargs (dict): Additional keyword arguments to pass to
21  `pd.read_csv`
22 
23  Returns
24  -------
25  DataFrame: containing data from the Google Sheets uptime
26  spreadsheet
27 
28  """
29  # Define url
30  url = domain + key + '/export?gid=' + gid + '&format=' + fmt
31 
32  # Read from CSV
33  df = pd.read_csv(url, **read_csv_kwargs)
34 
35  # Drop N/A rows
36  df = df.dropna()
37 
38  return df
39 
40 
def get_data_fy(domain, key, gid, fmt, read_csv_kwargs)
Definition: get_data.py:10