1
ファイルを反復して、インデックスと列に基づいてDataFrame
にセルの値を設定します。pandasデータフレームのセルに値を代入
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)
私は両方のファイルにエラー
File "pandas\index.pyx", line 137, in pandas.index.IndexEngine.get_loc (pandas\index.c:3979)
File "pandas\index.pyx", line 152, in pandas.index.IndexEngine.get_loc (pandas\index.c:3782)
File "pandas\index.pyx", line 178, in pandas.index.IndexEngine._get_loc_duplicates (pandas\index.c:4213)
File "pandas\index.pyx", line 385, in pandas.index.Int64Engine._maybe_get_bool_indexer (pandas\index.c:7683)
KeyError: '20150101'
下の列0を取得していますが、私はpandas
の両方csv
ファイルの読み込みの代わりsave_file
スルーループをお勧めしますインデックス
あなたのデータを2行で投稿できますか? – tmthydvnprt
あなたの 'save_file'を上書きすることを本当に*意味していますか? – tmthydvnprt