<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>
StarcoderdataJupyterStructuredCleanDedup