I have a dataframe that contains 13 different column names, I have separated these headings into two lists. I now want to perform different operations on each of these lists.
Is it possible to pass column names into pandas as a variable? My code at the moment can loop through the list fine but i am having trouble trying to pass the column name into the function
Code
CONT = ['age','fnlwgt','capital-gain','capital-loss']
#loops through columns
for column_name, column in df.transpose().iterrows():
if column_name in CONT:
X = column_name
print(df.X.count())
else:
print('')
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…