samedi 16 juillet 2016

Printing dataframe to .csv in python. TypeError:must be convertible to a buffer

I'm going through a dataframe and appending specific rows into a list. I'm then taking that list and trying to save it as a .csv file. However, I'm getting the following error: TypeError: must be convertible to a buffer, not DataFrame.

Any suggestions on what this is and how to fix this is greatly appreciated.

Here's some code:

my_list = []
my_list.append(df)

CSVdir = r"C:Users...."
realCSVdir = os.path.realpath(CSVdir)

if not os.path.exists(CSVdir):
    os.makedirs(CSVdir)


new_file_name = os.path.join(realCSVdir,'banana.csv')
new_file = open(new_file_name, 'wb')

for item in my_list:
    new_file.write(item)
    new_file.write("n")

Aucun commentaire:

Enregistrer un commentaire