python - Using pandas apply() function on a dataframe to create a new dataframe -


i have problem annoying me time now. have written function should, based on row values of dataframe, create new dataframe filled values based on condition in function. function looks this:

def inti():      df_ = pd.dataframe()     df_ = df_.fillna(0)      index, row in anno.iterrows():         genes=row['ar_genes'].split(',')         df=pd.dataframe()         if 'inti1' in genes:             df['year']=row['year']             df['integrase']= 1             df_=df_.append(df)         elif 'inti2' in genes:             df['year']=row['year']             df['integrase']= 1             df_=df_.append(df)         else:             df['year']=row['year']             df['integrase']= 0             df_=df_.append(df)      return df_ 

when call newdf=anno['ar_genes'].apply(inti()), following error:

typeerror: 'dataframe' object not callable 

i not understand why not work. have done similar things before, there seems difference not get. can explain wrong here?

*******************edit*****************************

anno in function dataframe function shal run on. contains string, example a,b,c,ad,c

dataframe.apply takes function applies rows/columns of dataframe. error occurs because function returns dataframe pass apply.

why do use .fillna(0) on newly created, empty, dataframe?

would not work? newdf = inti()


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -