python - Grouping Numpy Array and Returning Minimum Values -
i have ndarray this:
data = [(1,"yes", 54.234), (1,"yes", 1.0001), (2,"yes", 4.234), (3,"yes", 0.234)] dtypes = [("groupid", np.int), ("hasnear", "|s255"), ("distance", np.float64)] array = np.array(data, dtype=dtypes)
is there way group data , return minimum distance in each group in new array?
in example, have 4 rows. after group , return minimum, expect 3 rows returned. 1 each groupid value.
if numpy arrays aren't right tool, in pandas?
thank you
create pandas dataframe, group groupid , aggregate min()
:
df = pd.dataframe(data, columns=('groupid','hasnear','distance')) df.groupby('groupid').min()
Comments
Post a Comment