我正在遍历该文件,并希望根据索引和列设置DataFrame
中单元格的值。在
f = "D:/Technical_Data/1pep.csv"
df = pd.read_csv(f, header=0, sep=',')
save_file = "D:/Result_of_TA/" + "def.csv"
qbfile = open(save_file,"r")
for aline in qbfile.readlines():
values = aline.split(",")
if values[58].strip()=='BUY' :
no_of_shares = price/float(values[4])
if values[58].strip()=='SELL' :
price = no_of_shares * float(values[4])
df.ix[values[0],'Price'] = price
qbfile.close()
df.to_csv(save_file)
我正处于错误之下
^{pr2}$两个文件中的列0都是索引
我建议使用
pandas
同时读取csv
文件,而不是循环使用save_file
。然后,您可以创建各种索引方案和计算来将数据从qb
移动到1pep
。你可以这样构造你的代码现在你的代码还不清楚。{{cd7>可能有一些循环依赖关系。如果没有一些示例数据或结构说明,则无法建议具体代码。在
相关问题 更多 >
编程相关推荐