Set value for particular cell in pandas DataFrame using index

后端 未结 20 1854
野趣味
野趣味 2020-11-22 05:45

I\'ve created a Pandas DataFrame

df = DataFrame(index=[\'A\',\'B\',\'C\'], columns=[\'x\',\'y\'])

and got this

    x    y
A  NaN         


        
20条回答
  •  余生分开走
    2020-11-22 06:49

    I too was searching for this topic and I put together a way to iterate through a DataFrame and update it with lookup values from a second DataFrame. Here is my code.

    src_df = pd.read_sql_query(src_sql,src_connection)
    for index1, row1 in src_df.iterrows():
        for index, row in vertical_df.iterrows():
            src_df.set_value(index=index1,col=u'etl_load_key',value=etl_load_key)
            if (row1[u'src_id'] == row['SRC_ID']) is True:
                src_df.set_value(index=index1,col=u'vertical',value=row['VERTICAL'])
    

提交回复
热议问题