python - looping though a dataframe element by element -
if have data frame df (indexed integer)
bbg.kabn.s bbg.tka.s bbg.con.s bbg.isat.s index 0 -0.004881 0.008011 0.007047 -0.000307 1 -0.004881 0.008011 0.007047 -0.000307 2 -0.005821 -0.016792 -0.016111 0.001028 3 0.000588 0.019169 -0.000307 -0.001832 4 0.007468 -0.011277 -0.003273 0.004355
and want iterate though each element individually (by row , column) know need use .iloc(row,column) let me know if need create 2 loops (one row , 1 column) , how please?
i guess like:
for col in rollreturnrandomdf.keys(): row in rollreturnrandomdf.iterrows(): item = df.iloc(col,row)
but unsure of exact syntax. me out please?
maybe try using df.values.ravel()
.
import pandas pd import numpy np # data # ================= df = pd.dataframe(np.arange(25).reshape(5,5), columns='a b c d e'.split()) out[72]: b c d e 0 0 1 2 3 4 1 5 6 7 8 9 2 10 11 12 13 14 3 15 16 17 18 19 4 20 21 22 23 24 # np.ravel # ================= df.values.ravel() out[74]: array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]) item in df.values.ravel(): # item
Comments
Post a Comment