sophryu99 / TIL

TIL Repository
0 stars 1 forks source link

Pandas Dataframe Basics #11

Open sophryu99 opened 2 years ago

sophryu99 commented 2 years ago

Sort a dataframe by a column

number_of_roberries_weekdays_sorted.sort_values(by=['col1'])

Set a column of a dataframe as the index

number_of_roberries_weekdays_sorted.set_index('Day')

Drop a column by column name

X = df_tree.drop('gender', axis = 1)
sophryu99 commented 2 years ago

Renaming dataframe column names

df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
df.rename(columns={"A": "a", "B": "c"})
   a  c
0  1  4
1  2  5
2  3  6