python - Retrieve name of column from its Index in Pandas -
i have pandas dataframe , numpy array of values of dataframe. after work on numpy array, index of column , have row index of important value. need column name of particular value dataframe. after searching through documentations, found out can opposite not want. can any1 suggest way so.
i think need index columns names position (python counts 0
, fourth column need 3
):
colname = df.columns[pos]
sample:
df = pd.dataframe({'a':[1,2,3], 'b':[4,5,6], 'c':[7,8,9], 'd':[1,3,5], 'e':[5,3,6], 'f':[7,4,3]}) print (df) b c d e f 0 1 4 7 1 5 7 1 2 5 8 3 3 4 2 3 6 9 5 6 3 pos = 3 colname = df.columns[pos] print (colname) d
pos = [3,5] colname = df.columns[pos] print (colname) index(['d', 'f'], dtype='object')
Comments
Post a Comment