cudf.DataFrame.set_index#
- DataFrame.set_index(keys, drop=True, append=False, inplace=False, verify_integrity=False)[source]#
Return a new DataFrame with a new index
- Parameters:
- keysIndex, Series-convertible, label-like, or list
Index : the new index. Series-convertible : values for the new index. Label-like : Label of column to be used as index. List : List of items from above.
- dropboolean, default True
Whether to drop corresponding column for str index argument
- appendboolean, default True
Whether to append columns to the existing index, resulting in a MultiIndex.
- inplaceboolean, default False
Modify the DataFrame in place (do not create a new object).
- verify_integrityboolean, default False
Check for duplicates in the new index.
Examples
>>> df = cudf.DataFrame({ ... "a": [1, 2, 3, 4, 5], ... "b": ["a", "b", "c", "d","e"], ... "c": [1.0, 2.0, 3.0, 4.0, 5.0] ... }) >>> df a b c 0 1 a 1.0 1 2 b 2.0 2 3 c 3.0 3 4 d 4.0 4 5 e 5.0
Set the index to become the ‘b’ column:
>>> df.set_index('b') a c b a 1 1.0 b 2 2.0 c 3 3.0 d 4 4.0 e 5 5.0
Create a MultiIndex using columns ‘a’ and ‘b’:
>>> df.set_index(["a", "b"]) c a b 1 a 1.0 2 b 2.0 3 c 3.0 4 d 4.0 5 e 5.0
Set new Index instance as index:
>>> df.set_index(cudf.RangeIndex(10, 15)) a b c 10 1 a 1.0 11 2 b 2.0 12 3 c 3.0 13 4 d 4.0 14 5 e 5.0
Setting append=True will combine current index with column a:
>>> df.set_index("a", append=True) b c a 0 1 a 1.0 1 2 b 2.0 2 3 c 3.0 3 4 d 4.0 4 5 e 5.0
set_index supports inplace parameter too:
>>> df.set_index("a", inplace=True) >>> df b c a 1 a 1.0 2 b 2.0 3 c 3.0 4 d 4.0 5 e 5.0