[1]:
import pandas as pd
pd.set_option("display.max_rows", 2)
Rename¶
This function gives one or more columns new names. It returns a DataFrame with the renamed and original columns.
[2]:
from siuba import _, rename, select
from siuba.data import mtcars
small_cars = mtcars[["mpg", "cyl", "hp"]]
For example, the code below renames mpg
to be uppercase, while keeping the other columns of data.
[3]:
small_cars >> rename(MPG = "mpg")
[3]:
MPG | cyl | hp | |
---|---|---|---|
0 | 21.0 | 6 | 110 |
... | ... | ... | ... |
31 | 21.4 | 4 | 109 |
32 rows × 3 columns
It is equivalent to renaming in a select, while also selecting all other columns.
[4]:
small_cars >> select(_.MPG == _.mpg, _.cyl, _.hp)
[4]:
MPG | cyl | hp | |
---|---|---|---|
0 | 21.0 | 6 | 110 |
... | ... | ... | ... |
31 | 21.4 | 4 | 109 |
32 rows × 3 columns
Edit page on github here. Interactive version: