python - Appending dict to a dataframe -


new python. reading rows origin dataframe , trying append target dataframe. here program main code read each row of rawdata.

for i,row in raw_data.iterrows():     tool=row['entity']     shift=row['shift_info']     time=row['time_delta']     set_flag (tool,shift,time,raw_data,display_data) 

then construct dict append target dataframe.

def set_flag(tool,shift,time,raw_data,display_data):     j,rows in display_data.iterrows():           temp_col='time'+str(time)         if(rows['entity']==tool , rows['shift_info']==shift):             rows[temp_col]=1         else:          #   print tool                                       newrow = [{'shift_info':shift,'entity':tool,temp_col:1}]            #  print newrow             display_data = display_data.append(newrow, ignore_index=true) 

the code executes, display_data dataframe not changed. 1 can educate me problem? thank you!

try this

import copy  def set_flag(tool,shift,time,raw_data,display_data):     new_data = copy.deepcopy(display_data)     j,rows in display_data.iterrows():          temp_col='time'+str(time)         if(rows['entity']==tool , rows['shift_info']==shift):             rows[temp_col]=1         else:          #   print tool                                       newrow = [{'shift_info':shift,'entity':tool,temp_col:1}]            #  print newrow             new_data.append(newrow, ignore_index=true)     return new_data 

get new variable calling.

display_data = set_flag (tool,shift,time,raw_data,display_data) 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -