Skip to content

Instantly share code, notes, and snippets.

@WillKoehrsen
Last active September 26, 2018 13:03
Show Gist options
  • Save WillKoehrsen/62d67730e5a99cb71b22a3f6b9c49366 to your computer and use it in GitHub Desktop.
Save WillKoehrsen/62d67730e5a99cb71b22a3f6b9c49366 to your computer and use it in GitHub Desktop.
import pandas as pd
# Convert customer id to partition number
members['partition'] = members['msno'].apply(id_to_hash)
# Iteration through grouped partitions
for partition, grouped in members.groupby('partition'):
# Open file for appending
with open(file_dir + f'p{partition}/members.csv', 'a') as f:
# Write a new line and then the contents of the dataframe
f.write('\n')
grouped.to_csv(f, header = False, index = False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment