Home > Blockchain >  Select a specific field of a Pd.Dataframe
Select a specific field of a Pd.Dataframe

Time:06-28

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 e.g. df.iloc[5:6, 1:2]! is there another approach?

enter image description here

CodePudding user response:

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])

CodePudding user response:

Try this:

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

  • Related