简体   繁体   中英

Select a specific field of a Pd.Dataframe

Hi I have databases of different sizes! However, I would like to select only the Total column of the Values (red) for a calculation. But since this column is different for the different databases, I cannot write eg df.iloc[5:6, 1:2] ! is there another approach?

在此处输入图像描述

You can use .loc to access a row specified by its index.

df1 = pd.DataFrame(np.random.randn(3), index=["a", "b", "Total"])
df2 = pd.DataFrame(np.random.randn(5), index=["a", "b", "c", "d", "Total"])

print(df1.loc["index"].values[0])
print(df2.loc["index"].values[0])

尝试这个:

df.Value[df.ID=='Total']

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM