df_1 = pd.DataFrame(np.arange(9).reshape(3,3))
df_1.columns = ['col' + str(i) for i in df_1.columns]
str_colname = 'col1'
# df_1.str_colname # AttributeError: 'DataFrame' object has no attribute 'str_colname'
df_1[str_colname] # 可以
微信扫一扫
df_1 = pd.DataFrame(np.arange(9).reshape(3,3))
df_1.columns = ['col' + str(i) for i in df_1.columns]
str_colname = 'col1'
# df_1.str_colname # AttributeError: 'DataFrame' object has no attribute 'str_colname'
df_1[str_colname] # 可以
相关推荐