我想将数据存储在 CSV 文件的第二行。但它每次都会覆盖第一行。怎么做?我使用循环在第二行存储数据。但它没有发生。我有什么想念的吗?
import pandas as pd
import numpy as np
a=1
def table_driven_agent(percept):
location=['A','B']
status=['clean','dirty']
percepts=[]
table=[location,status]
percepts.append(percept)
action = tableDrivenVaccum(percept,table)
if action == 'dirty':
action = dirty(percept[1])
return(action)
def tableDrivenVaccum(percept,table):
for i in table:
if i[0] == percept[0]:
return(i[1])
def dirty(percept):
if percept == 'A':
return('Go to B')
elif percept =='B':
return('Go to A')
while( a<10):
percept = list(map(str,input("Enter the status and position:").split(',')))
action = table_driven_agent(percept)
print(action)
dict = {'action': action, 'percept': percept}
df= pd.DataFrame(dict)
df.to_csv(r'index.csv', index =False, header=True)
a=1
喵喔喔
慕盖茨4494581
相关分类