DEV Community

Nitin Bansal
Nitin Bansal

Posted on

20 useful pandas methods to spice-up your coding

  1. Use df.head() to display the first few rows of a DataFrame.
  2. Use df.tail() to display the last few rows of a DataFrame.
  3. Use df.info() to display the column data types and non-null values in a DataFrame.
  4. Use df.describe() to generate summary statistics for each column in a DataFrame.
  5. Use df.columns to view the column labels of a DataFrame.
  6. Use df.index to view the index labels of a DataFrame.
  7. Use df.rename() to rename columns or index labels in a DataFrame.
  8. Use df.sort_values() to sort a DataFrame by one or more columns.
  9. Use df.drop() to drop columns or rows from a DataFrame.
  10. Use df.loc[] to select rows or columns by label.
  11. Use df.iloc[] to select rows or columns by position.
  12. Use df.isnull() or df.notnull() to check for missing or non-missing values in a DataFrame.
  13. Use df.fillna() to fill missing values in a DataFrame with a specified value.
  14. Use df.dropna() to drop rows or columns with missing values in a DataFrame.
  15. Use df.pivot_table() to create a pivot table from a DataFrame.
  16. Use df.groupby() to group a DataFrame by one or more columns and perform an aggregation.
  17. Use df.merge() to combine two or more DataFrames based on common columns or index labels.
  18. Use df.join() to merge two or more DataFrames based on their index labels.
  19. Use df.apply() to apply a function to each row or column of a DataFrame.
  20. Use df.to_csv() to write a DataFrame to a CSV file.

Note: This article is actually written by chatGPT (https://chat.openai.com/chat)🤩

Top comments (0)