lambda).
try:
folder = pd.Series(df.logical_key.dropna().str.extract("([^/]+/?).*")[0].unique())
prefixes = folder[folder.str.endswith("/")].sort_values().tolist()
objects = folder[~folder.str.endswith("/")].sort_values().tolist()
except AttributeError:
// Pandas will raise an attribute error if the DataFrame has
// no rows with a non-null logical_key. We expect that case if
After Change
groups = df.groupby(df.logical_key.str.extract("([^/]+/?).*")[0], dropna=True)
folder = groups.agg(
size=("size", "sum"),
physical_key=("physical_key", "first")
)
folder.reset_index(inplace=True) // move the logical_key from the index to column[0]
folder.rename(columns={0: "logical_key"}, inplace=True) // name the new column
// Do not return physical_key for prefixes