pandas - Applying a python function that returns a list and writing to columns of dataframe -


is there way can apply function pandas dataframe returns list each row applied to, , take list , put each item new columns of existing dataframe?

for example function have returns given row list below of length 9

    [u'republic of congo permanent mission united nations',     u'embassy / consulate',     u'10021',     u'permanent mission of germany united nations',     u'embassy / consulate',     u'10021',     u'permanent mission of kenya united nations',     u'embassy / consulate',      u'10021'] 

and want store values in columns labeled:

     colnames= ['prop1_name', 'prop1_type', 'prop1_zip',         'prop2_name', 'prop2_type', 'prop2_zip',         'prop3_name', 'prop3_type', 'prop3_zip']  

right return of apply function list of lists each of inner lists 9 item list shown above. fine putting response new dataframe such below, haven't figured out how apply function write each new row each return or list of lists in right form.

   df_new = pd.dataframe(index=range(0,sample_size), columns=colnames) 

this should work

df_new.apply(lambda r: pd.series(function_taking_row(r), index=colnames), axis=1) 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -