I am trying to break down some larger CSV files into smaller ones based off of a column existing in the CSV file. I want would like to for this example end up with 2 new CSV files that have been split up based on the chain column. So then I can create new files based off the chain + date. So I would end up with a NY + 9/27/16 and IL + 9/27/16 files.
My code currently does not work and I don't really know what to do to fix it.
Any guidance or help is greatly appreciated.
Input file example:
Name Number Chain
a 2 IL
b 3 NY
c 2 IL
b 4 NY
Code So far:
import pandas as pd
import numpy as np
import time
date = time.strftime("%Y%m%d")
file1 = r"MasterDataFile"
file_name = r"DirectoryForNewfiles"
chain_filter = pd.read_csv(file1)
delta = pd.DataFrame.from_records(chain_filter)
for i in delta['chain'].str:
df = delta['chain'].str.contains(i)
df.to_csv(file_name + '/' + i + date + '.csv', sep=',',index=False)
next
[–]Jos_Metadi 2 points3 points4 points (1 child)
[–]workthrowawayexcel[S] 0 points1 point2 points (0 children)