<jupyter_start><jupyter_text>Recombining the partitions of each TSV file<jupyter_code>import pandas as pd
import os<jupyter_output><empty_output><jupyter_text>notes for pandas- `quoting=3` is needed to tell pandas to ignore all quotes. This works only because we stripped out `\r\n\t` characters previously, and turned off quote escaping in pyspark's `write.csv`.<jupyter_code>def mk_df(root, parts):
    data = []
    for p in parts:
        if 'csv' in p:
            try:
                tmp = pd.read_csv(root+'/'+p, sep='\t', quoting=3)
                data.append(tmp)
            except pd.errors.EmptyDataError:
                #some partitions won't have any data in them; this skips those
                pass

    if len(data) > 0:
        df = pd.concat(data)
    else:
        df = pd.DataFrame()
    
    return df
files = os.listdir('./')

for f in files:
    if f.endswith('tsv.parts'):
        name = f.rstrip('.parts')
        print name
        parts = os.listdir(f)
        df = mk_df(f, parts)
        df.to_csv(name, sep='\t', index=False)
        
print('Done!')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11659192825112108, 'fraction_numerical': 0.0026905829596412557, 'mean_word_length': 2.3716012084592144, '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': '646538', 'license': 'MIT', 'n_tokens_mistral': 380, 'n_tokens_neox': 362, 'n_words': 104, 'path': 'combine_tsv.ipynb', 'repo_name': 'RyC37/um_reddit', 'size': '1115'}