Trying to learn Python and managed to create a script that takes a csv, turns it into a data frame, changes the columns and then outputs a csv to the desired style.
Well what I need to do now is to be able to output multiple csvs based on the contents of my second column (first is the index, which I remove for output)
I have set up a parameter for unique data values and then a FOR loop to create filenames and output paths based on the unique data value.
But when I output the csv (data.to_csv), all 4 files are the same and unfiltered.
Here is my code
unique_code = data.import_code.unique()
for importcode in unique_import_codes:
#print("%s" % importcode)
filename = importcode.replace(".","") + ".csv"
#print("%s" % filename)
path = r"C:/myrequiredpath/"
#print("%s" % path)
data.to_csv(path+filename, index=False)
my data frame is called data import_code is my second column (not an index)
any ideas welcome!