You want to extract a value of a specific condition from a data frame.

Asked 2 years ago, Updated 2 years ago, 56 views

You want to extract values from a data frame based on specific conditions.

loc = pd.read_csv("./inference/output/temp.txt", sep=" ", header=None)
loc = loc.drop([5], axis=1)
loc.columns = ["classID", "x", "y", "width", "height"]
loc["x_lo"] = round(loc["x"] * 1080) #V50 medium resolution
loc["y_lo"] = round(loc["y"] * 2340)
display(loc)

The data frame was created as shown above. I'd like to extract the corresponding values of x_lo and y_lo under the condition of classIDd.

x_loc = loc.x_lo[loc["classID"] == "42"]
y_loc = loc.y_lo[loc["classID"] == "42"]

The value was not extracted and the series was declared

How can I extract the value of another row based on the classID?

python pandas dataframe

2022-09-20 20:49

1 Answers

Try loc.info(). I think classID is not string type but int type.


2022-09-20 20:49

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.