![](/img/trans.png)
[英]Python TypeError: must be convertible to a buffer, not OrderedDict
[英]Printing dataframe to .csv in python. TypeError:must be convertible to a buffer
我正在研究一個數據框,並將特定的行添加到列表中。 然后,我獲取該列表,並嘗試將其另存為.csv文件。 但是,我收到以下錯誤:TypeError:必須可轉換為緩沖區,而不是DataFrame。
非常感謝任何關於這是什么以及如何解決此問題的建議。
這是一些代碼:
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")
您正在尋找DataFrame.to_csv
:
for item in my_list:
item.to_csv(new_file)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.