第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 for 循環(huán)中更新數(shù)據(jù)幀

在 for 循環(huán)中更新數(shù)據(jù)幀

達令說 2021-06-16 17:27:51
我正在嘗試從 for 循環(huán)中的值創(chuàng)建數(shù)據(jù)框:d1 = {}d = {}for i in range(4000):   try:    shape_json = json.loads(region_shape[i])    file_name = file_name_nuclei[i]    x_val = shape_json["x"]    y_val = shape_json["y"]    width_val = shape_json["width"]    height_val = shape_json["height"]    path = '/home/values/' + str(file_name)    x1 = x_val    y1 = y_val    x2 = x_val + width_val    y2 = y_val + height_val    df = pd.DataFrame(data=d1)    d = {'col1': [path], 'col2': [x1], 'col3': [y1], 'col4': [x2], 'col5': [y2], 'col5': ['nucleus']}    df2 = pd.DataFrame(data=d1)    df.update(df2)   except:       pass但是,我無法在每次迭代中更新數(shù)據(jù)幀。任何人都可以幫忙嗎?我正在嘗試獲得輸出:0 col1 col2 col3 col4 col5  '/home/values/image.png' 23 55 30 62 'nucleus'  '/home/values/image2.png' 40 72 37 92 'nucleus'.....
查看完整描述

2 回答

?
子衿沉夜

TA貢獻1828條經(jīng)驗 獲得超3個贊

我會創(chuàng)建一個列表并將所有數(shù)據(jù)幀添加到循環(huán)中的列表中,然后在最后使用 pd.concat:


results = []


for i in range(4000):

    try:

        shape_json = json.loads(region_shape[i])

        file_name = file_name_nuclei[i]


        x_val = shape_json["x"]

        y_val = shape_json["y"]

        width_val = shape_json["width"]

        height_val = shape_json["height"]


        path = '/home/values/' + str(file_name)


        x1 = x_val

        y1 = y_val


        x2 = x_val + width_val

        y2 = y_val + height_val


        d = {'col1': [path], 'col2': [x1], 'col3': [y1], 'col4': [x2], 'col5': [y2], 'col5': ['nucleus']}

        df = pd.DataFrame(data=d)


        results.append(df) # append this loop's df to your list of dataframes

    except:

        pass


final_df = pd.concat(results) 


查看完整回答
反對 回復 2021-06-22
?
眼眸繁星

TA貢獻1873條經(jīng)驗 獲得超9個贊

您需要在循環(huán)之外創(chuàng)建一個“主”數(shù)據(jù)框。


d1 = {}

d = {}


df = pd.DataFrame(data=d1)


for i in range(4000):

    try:

        shape_json = json.loads(region_shape[i])

    file_name = file_name_nuclei[i]


    x_val = shape_json["x"]

    y_val = shape_json["y"]

    width_val = shape_json["width"]

    height_val = shape_json["height"]


    path = '/home/values/' + str(file_name)


    x1 = x_val

    y1 = y_val


    x2 = x_val + width_val

    y2 = y_val + height_val


    d = {'col1': [path], 'col2': [x1], 'col3': [y1], 'col4': [x2], 'col5': [y2], 'col5': ['nucleus']}

    df2 = pd.DataFrame(data=d1)


    df.update(df2)




    except:

        pass

并且 d1 在所有代碼中都是空的。當您嘗試使用 df2 更新 df 時,df2 也是空的。


查看完整回答
反對 回復 2021-06-22
  • 2 回答
  • 0 關(guān)注
  • 111 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號