<jupyter_start><jupyter_text>Slicing monthly files only keep hemisphere='N' only keep dates since Jan 1999 validate that "missing" columns are zeroes and drop themThen set index to date.<jupyter_code>monthly.shape
monthly = monthly[monthly['hemisphere'] == 'N']
monthly.shape
monthly.loc[:,'date'] = pd.to_datetime(monthly['month'])
# Set the month column to the DataFrame index
monthly.set_index('date', inplace=True, verify_integrity=True, drop=True)
monthly = monthly[monthly.index > '1998-12-31']
monthly.columns
monthly.shape
for column in monthly.columns:
    matched = re.search(r"missing_km2", column)
    if matched:
        print("%s: " % (column))
        print(monthly[column].min(), monthly[column].max())
        del monthly[column]
monthly.shape
monthly['meier2007_laptev_area_km2'].plot()
fig, ax = plt.subplots(15, figsize=(8,25))
i = 0
for column in monthly.columns:
    matched = re.search(r"area_km2", column)
    if matched:
        print("%s: %d" % (column, i))
        monthly[column].plot(ax=ax[i], sharey=True, title=column)
        i = i + 1
fig.tight_layout()
fig.savefig("nsidc0051_area_by_region.png")<jupyter_output><empty_output><jupyter_text>Convert from monthly time series to years time series<jupyter_code>monthly
def convert_column_to_matrix(df, column):
    short_column = column
    short_column = re.sub("meier2007_", "", short_column)
    nyears = 17
    nmonths = 12
    years = np.arange(nyears) + 1999
    months = np.arange(nmonths) + 1
    column_names = ["%02d_%s" % (month, short_column) for month in months]
    data = pd.DataFrame(index=years, columns=column_names)
    for year in years:
        for month in months:
            yyyymm = "%4d-%02d" % (year, month)
            data.loc[year, column_names[month-1]] = df.get_value(
                index=pd.to_datetime(yyyymm), col=column)
    return(data)
start=True
for column in monthly.columns:
    matched = re.search(r"area_km2|extent_km2", column)
    if matched:
        print("%s: " % (column))
        new = convert_column_to_matrix(monthly, column)
        if start: 
            all = new.copy()
            start=False
        else:
            all = pd.concat([all, new], axis=1)
all.shape
all
col = 'beaufort_extent_km2'

print("from monthly: %f" % monthly.get_value(index=pd.to_datetime('2008-06-01'), col='meier2007_'+col))
print("from all    : %f" % all.get_value(index=2008, col='06_' + col))
del monthly['month']
monthly.to_csv('nsidc0051_monthly_tseries.csv', sep='\t')
all.to_csv('nsidc0051_year_by_month.csv', index_label='Year')
%pwd
%more nsidc0051_year_by_month.csv
all.columns<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1371580547112462, 'fraction_numerical': 0.031534954407294834, 'mean_word_length': 4.053742802303263, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '406966', 'license': 'Apache-2.0', 'n_tokens_mistral': 982, 'n_tokens_neox': 923, 'n_words': 197, 'path': 'modice/sii_monthly_for_modice.ipynb', 'repo_name': 'mjbrodzik/ipython_notebooks', 'size': '2632'}