I am trying to plot some histograms of the values in the columns of a dataframe in pandas and I want to loop over the columns for a compact code but the code keeps throwing an error?
for c in df.columns:
axes[i,0].hist(df[df.num>0].c.tolist())
i +=1
AttributeError: 'DataFrame' object has no attribute 'c'
Chain column can not use in the for loop
axes[i,0].hist(df.loc[df.num>0,c].tolist())
You can't use dot notation with variables. I think what you want to go for is
for c in df.columns:
axes[i,0].hist(df[df.num>0][c].tolist())
i +=1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.