How can I use a string in a loop to be used in a dataframe command? Using Python 3 -
say have dataframe named population
contains series age
, education
. interested in running command pd.qcut
example age
write pd.qcut(population.age.values, [0, .25, .5, .75, 1],['a','b','c','d'])
.
i each column (and replace each column) in loop form, as:
col_name = ['age', 'education'] in col_name: population.i=pd.qcut(population.i.values, [0, .25, .5, .75, 1],['a','b','c','d'])
but cannot find right function opens string me in population.i.values
. tried poped(i)
didn't work.
thanks in advance.
you have use population[i]
instead of population.i
.
the pandas documentation indexing explain how access series corresponding colname
doing frame[colname]
.
when doing population.i
(called attribute access in doc) pandas looking columns names 'i'
.
Comments
Post a Comment