8c Pandas III

Cards (9)

  • sort_values()

    Method to sort a dataframe by a particular column
  • Default is to sort in ascending order (smallest first)
  • sort_values(by = 'col_name', ascending = False)
    Sort in descending order (biggest first)
  • Using sort_values() doesn't change the actual dataframe, it simply shows us the sorted values without changing the actual data
  • sort_values(by = 'col_name', inplace = True)
    Sort the dataframe in place, changing the actual dataframe
  • df.rename(columns = {'old1': 'new1', 'old2': 'new2', 'old3': 'new3'}, inplace = True)

    Rename columns in a dataframe
  • To remove one or more columns, use the drop() method
  • df.dropna(inplace = True)

    Remove all rows that contain missing values
  • df.drop_duplicates(inplace = True)

    Remove all rows that are duplicates of other rows