Friday, January 27, 2023

Must Know Python Pandas Data Wrangling Commands

Here are some common data wrangling commands in Pandas:

  1. df.head() and df.tail() to view the first and last few rows of a DataFrame, respectively.
  2. df.shape to see the number of rows and columns in a DataFrame.
  3. df.info() to get a summary of the DataFrame, including the number of non-null values in each column.
  4. df.describe() to get basic statistics of numeric columns in a DataFrame.
  5. df.columns to see the column names in a DataFrame.
  6. df.rename(columns={'old_name':'new_name'}) to rename columns in a DataFrame.
  7. df.sort_values(by='column_name') to sort a DataFrame by a specific column.
  8. df.groupby('column_name').mean() to group a DataFrame by a specific column and take the mean of each group.
  9. df.pivot_table(values='column_name', index='grouping_column', columns='aggregating_column') to create a pivot table.
  10. df.apply(function) to apply a function to each element in a DataFrame.
  11. df.dropna() to drop rows with missing values.
  12. df.fillna(value) to fill missing values with a specific value.

No comments: