def merge(df1, df2, monthly=False):
    """
    Merge two dataframes

    :param df1: (pd.DataFrame) - dataframe to merge
    :param df2: (pd.DataFrame) - another dataframe to merge
    :param monthly: (boolean) - whether to groupby month first
    :return merged_df: (pd.DataFrame) - combined df1 and df2
    """
    if monthly:
        df1 = df1.groupby('1M').mean()
        df2 = df2.groupby('1M').mean()
    return df1.merge(df2,
                     how='outer',
                     left_index=True,
                     right_index=True)