<jupyter_start><jupyter_text>Summarize Sci-Hub visitor logs by DOI<jupyter_code>import pandas
log_df = pandas.read_table('scihub-logs_2015-09_2016-02.tsv.xz')
log_df['day'] = log_df.date.str.slice(stop=10)
log_df['month'] = log_df.date.str.slice(stop=7)
log_df.head(3)
len(log_df)
function_mapper = {
    'doi': 'count',
    'IP_code': pandas.Series.nunique,
    'country': pandas.Series.nunique,
    'day': pandas.Series.nunique,
    'month': pandas.Series.nunique,
}

renamer = {
    'doi': 'downloads',
    'IP_code': 'visitors',
    'country': 'countries',
    'day': 'days',
    'month': 'months',
}

summary_df = (
    log_df
    .groupby('doi')
    .aggregate(function_mapper)
    .rename(columns=renamer)
    .reset_index()
)
summary_df.head(2)
len(summary_df)
summary_df.to_csv('./scihub-logs-summary_2015-09_2016-02.tsv.xz', sep='\t', compression='xz', index=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17900552486187846, 'fraction_numerical': 0.032044198895027624, 'mean_word_length': 4.6625, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '408383', 'license': 'CC0-1.0', 'n_tokens_mistral': 399, 'n_tokens_neox': 368, 'n_words': 49, 'path': 'download/scihub-logs/2.summarize.ipynb', 'repo_name': 'arielsvn/scihub', 'size': '905'}