Pandas Methood

Sadat Mahmud
0

 




Here’s a list of common methods in pandas that you can use for various data manipulation tasks. I've categorized them based on functionality:


Basic Methods:

  1. pd.read_csv() — Load CSV files into a DataFrame.

  2. df.head() — View the first 5 rows of a DataFrame.

  3. df.tail() — View the last 5 rows of a DataFrame.

  4. df.info() — Summary of DataFrame with types, non-null counts, etc.

  5. df.describe() — Get a statistical summary of the DataFrame.

  6. df.shape — Get the number of rows and columns.

  7. df.columns — Get the column labels of a DataFrame.

  8. df.dtypes — Check the data types of columns.

  9. df.set_index() — Set a column as the index.

  10. df.reset_index() — Reset the index to default.


Accessing and Selecting Data:

  1. df.loc[] — Access rows and columns by labels (slicing).

  2. df.iloc[] — Access rows and columns by index (integer-based).

  3. df.at[] — Access a single value for a row/column pair.

  4. df.iat[] — Access a single value for a specific row/column.

  5. df['column_name'] — Access a single column.

  6. df[['col1', 'col2']] — Access multiple columns.

  7. df.iloc[condition] — Access rows based on conditions (e.g., df.iloc[df['col'] > 10]).


Manipulating Data:

  1. df.drop() — Drop a row/column from the DataFrame.

  2. df.dropna() — Drop missing values.

  3. df.fillna() — Fill missing values with a specific value or method.

  4. df.rename() — Rename columns or index labels.

  5. df.assign() — Assign new columns to the DataFrame.

  6. df.insert() — Insert a new column at a specific position.

  7. df.append() — Append rows to a DataFrame.

  8. df.concat() — Concatenate multiple DataFrames along rows or columns.

  9. df.merge() — Merge two DataFrames based on a common column.

  10. df.join() — Join two DataFrames based on the index.

  11. df.replace() — Replace values in a DataFrame.

  12. df.apply() — Apply a function along an axis (rows/columns).


Filtering and Querying:

  1. df.query() — Query the DataFrame using a string expression.

  2. df[condition] — Filter rows based on conditions (e.g., df[df['age'] > 30]).

  3. df.str.contains() — Filter strings containing a pattern.

  4. df.str.match() — Filter strings matching a regex pattern.

  5. df.isna() — Detect missing values.

  6. df.notna() — Detect non-missing values.

  7. df.isnull() — Check for null values.

  8. df.notnull() — Check for non-null values.


Aggregation and Transformation:

  1. df.groupby() — Group data based on columns and apply aggregation.

  2. df.aggregate() — Apply aggregate functions to data.

  3. df.mean() — Calculate the mean of a column.

  4. df.sum() — Calculate the sum of a column.

  5. df.min() — Find the minimum value in a column.

  6. df.max() — Find the maximum value in a column.

  7. df.count() — Count non-null values in a column.

  8. df.cumsum() — Compute the cumulative sum.

  9. df.cumprod() — Compute the cumulative product.

  10. df.transform() — Apply a function elementwise to each group.


Date/Time Operations:

  1. pd.to_datetime() — Convert to datetime type.

  2. df['date'].dt.year — Extract year from a datetime column.

  3. df['date'].dt.month — Extract month from a datetime column.

  4. df['date'].dt.day — Extract day from a datetime column.

  5. df['date'].dt.weekday — Extract weekday (0 = Monday, 6 = Sunday).

  6. df['date'].dt.date — Extract date (without time).


Sorting and Ranking:

  1. df.sort_values() — Sort DataFrame by values in one or more columns.

  2. df.sort_index() — Sort DataFrame by index.

  3. df.rank() — Rank the values in a column.


Pivoting and Reshaping Data:

  1. df.pivot() — Pivot the DataFrame (reshaping data).

  2. df.pivot_table() — Create a pivot table.

  3. df.melt() — Unpivot the DataFrame from wide to long format.

  4. df.stack() — Stack the columns into rows (reshape).

  5. df.unstack() — Unstack rows into columns.


Data Type Conversion:

  1. df.astype() — Convert data types of columns.

  2. df.to_numeric() — Convert a column to numeric values.

  3. df.to_datetime() — Convert a column to datetime.


Rolling and Window Functions:

  1. df.rolling() — Create a rolling view of a DataFrame for window-based operations.

  2. df.rolling(window=5).mean() — Calculate the rolling mean over a window of size 5.

  3. df.expanding() — Apply expanding window operations (i.e., cumulative).


Other Useful Methods:

  1. df.pivot_table() — Create a pivot table for summarizing data.

  2. df.to_csv() — Save DataFrame to a CSV file.

  3. df.to_excel() — Save DataFrame to an Excel file.

  4. df.to_json() — Save DataFrame to a JSON file.

  5. df.memory_usage() — Get memory usage of DataFrame columns.


Lambda Functions:

  1. df.apply(lambda x: x * 2) — Apply a lambda function elementwise on the DataFrame.


This list should give you a wide variety of methods to handle different tasks in pandas

āĻāĻ•āϟি āĻŽāύ্āϤāĻŦ্āϝ āĻĒোāϏ্āϟ āĻ•āϰুāύ

0āĻŽāύ্āϤāĻŦ্āϝāϏāĻŽূāĻš

āĻāĻ•āϟি āĻŽāύ্āϤāĻŦ্āϝ āĻĒোāϏ্āϟ āĻ•āϰুāύ (0)