<jupyter_start><jupyter_text>Generate a dataset in the form of a .csv file from MongoDB instance running locally<jupyter_code>import pandas as pd
from pymongo import MongoClient

small_dataset = True  # Sampling the dataset for training and testing purposes - to support systems with lowered performance
sample_size = 10000
start_year = '07'
end_year = '22'
size_cutoff = 220000  # Maximum value: 740000

# Connect to local instance of MongoDB
client = MongoClient('127.0.0.1', 27017)
db = client.frtp
collection = db.documents

# Extract all the data available with specific restrictions
result = collection.find({
    "year": {
        '$lt': end_year,
        '$gte': start_year
    },
    "size": {
        '$lt': size_cutoff
    }
})

# Save the data ready for Drive upload
df = pd.DataFrame(list(result))
df['year'] = pd.to_datetime(df['year'], format='%y')
if small_dataset:
    df = df.sample(n=sample_size)
    df.to_csv(f'collab_dataset_small_{start_year}_{end_year}_<{size_cutoff}.csv')
else:
    df.to_csv(f'collab_dataset_{start_year}_{end_year}_<{size_cutoff}.csv')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11361587015329125, 'fraction_numerical': 0.028854824165915238, 'mean_word_length': 4.6923076923076925, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '395360', 'license': 'MIT', 'n_tokens_mistral': 395, 'n_tokens_neox': 363, 'n_words': 99, 'path': 'collab/generate_dataset_collab.ipynb', 'repo_name': 'armandanusca/topic-modelling-risk-factors', 'size': '1109'}