python - pandas edit a cell value with itertuples -
i speed code, don't use double for: code:
c in range(0, n-1): l in range(0,n-c-1): df2.ix[l,c]=c_back(l,c,df) i use
for x in df.itertuples(): but don't know how modify specific cell value. thanks
use stack
for mytuple, value in df.stack().iteritems(): print(mytuple, value) consider df
df = pd.dataframe(np.arange(9).reshape(-1, 3), list('abc'), list('xyz')) df for mytuple, value in df.stack().iteritems(): print(mytuple, value) ('a', 'x') 0 ('a', 'y') 1 ('a', 'z') 2 ('b', 'x') 3 ('b', 'y') 4 ('b', 'z') 5 ('c', 'x') 6 ('c', 'y') 7 ('c', 'z') 8 to set values of df
for (i, j), value in df.stack().iteritems(): df.set_value(i, j, value ** 2) df 

Comments
Post a Comment