python - Create DataFrame from list of rows, and Iterate Over it -


note - asked question assuming issue dataframe constructor, issue iterrows()

i create pandas dataframe list rows, each row list of values. have tried following:

multigram_counts = [     ["happy birthday", 23],     ["used below", 10],     ["frame for", 2] ] df = pd.dataframe(multigram_counts, columns = ["phrase", "count"]) df_iter = df.iterrows() frow = df_iter.next() self.assertequal(frow['phrase'], "happy birthday") 

but following error:

typeerror: tuple indices must integers, not str 

how fix both arguments in "assertequal" function indeed equal? is, frow['phrase'] equal "happy birthday".

df_iter contains (index, row) tuple, row only, try this:

f_index, frow = df_iter.next() 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -