python - Sorting through list and storing distinct values -
so i'm using pandas read data looks this:
0 overcast 1 overcast 2 overcast 3 overcast 4 rainy 5 rainy 6 rainy 7 rainy 8 rainy 9 sunny 10 sunny 11 sunny 12 sunny 13 sunny
and wish store overcast (first entry) variable, , iterate through list until there contrasting variable, , store 1 also. should assign other contrasting variables along way until until end of list.
i'm having hard time figuring out best way or maybe there in pandas me i'm missing?
edit: want start @ position [0,0] 'overcast' , make variable a , run down list until hits 'rainy' point stores in b, 'sunny' c, etc. want understand how make robust no matter amount of labels, it'll store it. not hilbert's hotel big couple hundred.
pandas offers unique()
method identify distinct values of column. can transpose row.
>>> df2 = pd.dataframe(df.unique()).t # t = transpose() 0 1 2 0 overcast rainy sunny
or following rename columns. (i can't tell if want them row names or row values.)
>>> df2.columns = df.unique() overcast rainy sunny 0 overcast rainy sunny
Comments
Post a Comment