Pandas DataFrame 單元作為計(jì)數(shù)器我正在嘗試創(chuàng)建一個(gè)熊貓數(shù)據(jù)幀“B”,同時(shí)考慮到另一個(gè)數(shù)據(jù)幀“A”的逐行讀取。問題是我想填充新數(shù)據(jù)幀“B”的單元格值,計(jì)算第一個(gè)數(shù)據(jù)集“A”中發(fā)生的特定情況。我不能用全零初始化數(shù)據(jù)幀“B”,因?yàn)槲也恢浪鼘⒂卸嗌傩?。如果我不初始?DataFrame "B" 的單元格值,我會(huì)收到此錯(cuò)誤KeyError: "the label ['0'] is not in the [index]"當(dāng)我嘗試:for i in range(len(df_A.index)): if (int(df_A.iloc[i][3])) == sec_types_crmc[3]: df_B.at["'"+str(i)+"'", 'bin_0'] = df_B.loc["'"+str(i)+"'"]['bin_0'] + 1
添加回答
舉報(bào)
0/150
提交
取消