uid iid val uid 1 1 1 5 5.5 2 3 1 4 3.5 2 2 1 4 3.5 2 7 1 4 3.5 2 9 1 4 3.5 2 11 1 4 3.5
From the data frame above, I want to remove the first column, which:
uid 1 2 2 2 2 2
and remove
uid iid val 1 1 5 5.5 3 1 4 3.5 2 1 4 3.5 7 1 4 3.5 9 1 4 3.5 11 1 4 3.5
Can anyone help?
You can avoid the inclusion uidin the index, in the first place, passing group_keys=Falseingroupby
uid
group_keys=False
groupby
df.groupby('uid', group_keys=False).apply(lambda x: x.tail(len(x) // 5)) uid iid val 4 1 5 5.5
Use reset_indexor droplevel:
reset_index
droplevel
df = df.reset_index(level=0, drop=True) df = df.reset_index(level='uid', drop=True)
Or:
df.index = df.index.droplevel(0)
you can set as_indexhow Falseto remove the index from grouped by df.
as_index
False
df.groupby('uid', as_index=False)
Source: https://habr.com/ru/post/1675015/More articles:How to build a family of functions in ggplot2 - rChange user password using woocommerce rest api in Android - androidHighlight a function with multiple arguments in R - rHow to filter history based on gitignore? - gitКак добавить проверку формы вместе с предупреждениями - javascriptHow to get user id using username in io socket - javaЗагрузка данных перед всем тестовым случаем и уничтожение после всего теста - javaR - The fastest way to find the closest value in a vector is rWill WebAssembly make the Audio API and WebGL obsolete? - webassemblyHow to update component state with value from reduction state in reduction reaction? - javascriptAll Articles