我想使用变量插入iloc参数
attribute_name = ['CP_ST', 'CP_ES', 'CP_AD', 'CP_ININ', 'CP_IMIN', 'CP_CL', 'CP_CF', 'CP_SM', 'CP_TL', 'CP_COV']
indices = 1
list_of_attr = ""
for str in attribute_name :
if(indices != len(attribute_name)):
list_of_attr += "'" + str + "'"
list_of_attr += ","
indices +=1
else:
list_of_attr += "'" + str + "'"
indices +=1
hope_df = hope_df.loc[ : , [list_of_attr] ]
我想将“ list_of_attr”传递给iloc函数
答案 0 :(得分:0)
您应该直接在列表中传递属性名称:
attribute_name = ['CP_ST', 'CP_ES', 'CP_AD', 'CP_ININ', 'CP_IMIN', 'CP_CL', 'CP_CF', 'CP_SM', 'CP_TL', 'CP_COV']
hope_df = hope_df.loc[ : , attribute_name ]