def get_dataframe_by_definition(def_dict):
    """Return dataframe corresponding to definition dict."""   
    file_path = os.path.join(def_dict['folder'], def_dict['filename'])
    if 'anchor' in def_dict.keys():
        gen = read_sheet(file_path, def_dict['sheet'], def_dict['anchor']) 
    else:
        gen = read_sheet(file_path, def_dict['sheet'])
    try:
       df = get_dataframe(gen)[Regions.names()]
    except:
       raise ValueError(file_path)    
    df.insert(0, 'varname', def_dict['varname'])
    return df 
def get_dataframe_by_definition(def_dict):
    """Return dataframe corresponding to definition dict."""
    file_path = os.path.join(def_dict['folder'], def_dict['filename'])
    if 'anchor' in def_dict.keys():
        gen = read_sheet(file_path, def_dict['sheet'], def_dict['anchor'])
    else:
        gen = read_sheet(file_path, def_dict['sheet'])
    try:
        df = get_dataframe(gen)[Regions.names()]
    except:
        raise ValueError(file_path)
    df.insert(0, 'varname', def_dict['varname'])
    return df
from datetime import date
import pandas as pd
import os

from xls_read import read_sheet, read_by_definition, yearmon
from regions import Regions

filter_region_name = Regions.filter_region_name
reference_region_names = Regions.names()
rf_name = Regions.rf_name()
district_names = Regions.district_names()
summable_regions = Regions.summable_regions()

def get_dataframe(datapoints_stream):
    """Return dataframe corresponding to datapoints stream."""        
    list_of_dicts = [{'val':x[0], 'region':x[1], 'dates':x[2]} for x in datapoints_stream]
    df = pd.DataFrame(list_of_dicts)
    df = df.pivot(columns='region', values='val', index='dates')[reference_region_names]
    df.index = pd.DatetimeIndex(df.index)
    return df

def get_dataframe_by_definition(def_dict):
    """Return dataframe corresponding to definition dict."""   
    file_path = os.path.join(def_dict['folder'], def_dict['filename'])
    if 'anchor' in def_dict.keys():
        gen = read_sheet(file_path, def_dict['sheet'], def_dict['anchor']) 
    else:
        gen = read_sheet(file_path, def_dict['sheet'])
    try:
       df = get_dataframe(gen)[Regions.names()]
    except:
import os
import sys
import pandas as pd

from getter import get_dataframe_by_definition

from regions import Regions
filter_region_name = Regions.filter_region_name
reference_region_names = Regions.names()

from definitions import definitions

# -------------------------------------------------------------------------
# Defintions
# -------------------------------------------------------------------------

from config import XL_SAMPLE_FOLDER

source_def_sample = {
    'varname': 'PPI_PROM_ytd',
    'folder': XL_SAMPLE_FOLDER,
    'filename': 'industrial_prices.xls',
    'sheet': 'пром.товаров',
    'anchor': 'B5',
    'anchor_value': 96.6
}

def_dict_2 = {
    'varname': 'SHIPMENTS',
    'folder': XL_SAMPLE_FOLDER,
    'filename': 'shipment.xls',