pandas逐行追加到csv的正确方式:
# ---encoding:utf-8---
# @Author : STZZ AIOT TLZS
# @Email :stzzaiottlzs@gmail.com
# @Site : AIOT
# @File : 逐行追加到csv文件.py
# @Software: PyCharm
import pandas as pd
def append_to_csv():
data_df = pd.DataFrame(columns=["a", "b"])
data_df.loc[0] = ["1", "11"]
data_df.to_csv("test.csv", mode="a", index=False, encoding="utf-8")
data_df.loc[0] = ["2", "22"]
data_df.to_csv("test.csv", mode="a", index=False, header=False, encoding="utf-8")
def __test_append_to_csv__():
append_to_csv()
if __name__ == '__main__':
__test_append_to_csv__()
