簡體   English   中英

遍歷 pandas 中 dataframe 的列

[英]iterating over the columns of a dataframe in pandas

我正在嘗試 pandas 中的 dataframe 列中的值的一些直方圖 plot 並且我想在列上循環循環以獲取壓縮代碼

for c in df.columns:
    axes[i,0].hist(df[df.num>0].c.tolist())
    i +=1
AttributeError: 'DataFrame' object has no attribute 'c'

鏈柱不能在for循環中使用

axes[i,0].hist(df.loc[df.num>0,c].tolist())

您不能對變量使用點表示法。 我想你想要 go 是為了

for c in df.columns:
    axes[i,0].hist(df[df.num>0][c].tolist())
    i +=1

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM