pandas function index
Search common pandas constructors, methods, and operations by name or task.
Search by function name or task, then expand an entry for a short explanation and example. The examples assume import pandas as pd; they use small in-memory DataFrames to focus on the operation rather than file setup.
Pandas APIs evolve, so check the official API reference for complete signatures, dtype details, and version-specific behavior. Avoid relying on private namespaces such as pandas.core.
Sources: pandas API reference, 10 minutes to pandas, Indexing and selecting data
21 results in 4 categories
Create and read data
Construct Series and DataFrames or load common file formats.
pd.Series / pd.DataFramepd.Series(data) | pd.DataFrame(data)Create a labeled one-dimensional or two-dimensional data structure.
A Series has an index; a DataFrame has row and column labels. Pass explicit indexes when labels carry meaning.
import pandas as pd
import pandas as pd
scores = pd.Series([80, 95], index=["Ari", "Bea"])
frame = pd.DataFrame({"name": ["Ari", "Bea"], "score": [80, 95]})pandas documentation pd.read_csvpd.read_csv(filepath, ...)Read a CSV file into a DataFrame.
Common options include usecols, dtype, parse_dates, and na_values. Inspect the result after loading.
import pandas as pd
df = pd.read_csv("sales.csv", parse_dates=["date"])
print(df.shape)pandas documentation pd.read_excelpd.read_excel(io, sheet_name=0, ...)Read an Excel worksheet into a DataFrame.
Choose a sheet by name or position. Excel support may require an optional engine package.
import pandas as pd
df = pd.read_excel("sales.xlsx", sheet_name="Orders")pandas documentation DataFrame.to_csvdf.to_csv(path, index=False, ...)Write a DataFrame to a CSV file.
Choose whether row labels belong in the file; index=False is common for exporting a table.
import pandas as pd
df.to_csv("clean-sales.csv", index=False)pandas documentation Inspect and select
Understand a table and choose the rows or columns you need.
DataFrame.head / taildf.head(n=5) | df.tail(n=5)Preview the first or last rows.
Useful for a quick visual check; they do not replace validating schema, nulls, and row counts.
import pandas as pd
print(df.head(3))
print(df.tail(2))pandas documentation DataFrame.infodf.info()Print column types, non-null counts, and memory details.
A compact first inspection after reading a file.
import pandas as pd
df.info()pandas documentation DataFrame.describedf.describe()Summarize numeric columns with common statistics.
Use include options when you also want summaries of non-numeric columns.
import pandas as pd
print(df.describe())pandas documentation df.loc / df.ilocdf.loc[row_labels, columns] | df.iloc[row_positions, column_positions]Select data by labels or integer positions.
Use loc for index and column labels; use iloc for zero-based positions.
import pandas as pd
first_row = df.iloc[0]
selected = df.loc[df["score"] >= 80, ["name", "score"]]pandas documentation DataFrame.querydf.query(expression)Filter rows using a readable expression string.
For user-provided values, use the documented @variable syntax rather than interpolating text into an expression.
import pandas as pd
minimum = 80
high_scores = df.query("score >= @minimum")pandas documentation DataFrame.sort_valuesdf.sort_values(by, ascending=True)Return rows ordered by one or more columns.
Use ascending=False for descending order. The result is a new DataFrame unless inplace behavior is explicitly requested.
import pandas as pd
ranked = df.sort_values("score", ascending=False)pandas documentation Clean and transform
Handle missing data and create useful derived columns.
DataFrame.isnadf.isna()Mark missing values with True.
Use .sum() to count missing entries per column. Empty strings are not automatically considered missing.
import pandas as pd
missing_by_column = df.isna().sum()
print(missing_by_column)pandas documentation DataFrame.dropna / fillnadf.dropna(...) | df.fillna(value)Remove missing observations or fill missing entries.
Choose a policy that preserves the meaning of the data; filling with zero is not always valid.
import pandas as pd
complete = df.dropna(subset=["score"])
filled = df.fillna({"score": df["score"].median()})pandas documentation DataFrame.drop_duplicatesdf.drop_duplicates(subset=None, keep="first")Return a table with duplicate rows removed.
Specify the fields that define a duplicate. Identical names do not necessarily represent the same entity.
import pandas as pd
unique_orders = df.drop_duplicates(subset=["order_id"])pandas documentation DataFrame.astypedf.astype(dtype)Convert one or more columns to specified dtypes.
Conversion fails for incompatible values. Use pd.to_numeric or pd.to_datetime with an explicit error policy for parsing.
import pandas as pd
df["units"] = df["units"].astype("Int64")pandas documentation pd.to_numeric / pd.to_datetimepd.to_numeric(values, errors="raise") | pd.to_datetime(values, ...)Parse values into numeric or datetime representations.
errors="coerce" converts parse failures to missing values; inspect these before deciding how to handle them.
import pandas as pd
df["price"] = pd.to_numeric(df["price"], errors="raise")
df["date"] = pd.to_datetime(df["date"], errors="raise")pandas documentation DataFrame.assigndf.assign(new_column=values)Return a DataFrame with one or more derived columns.
Useful for clear transformations and method chains; the original DataFrame is not changed.
import pandas as pd
with_revenue = df.assign(revenue=df["units"] * df["unit_price"])pandas documentation Summarize and combine
Aggregate groups, join tables, and reshape summaries.
DataFrame.groupbydf.groupby(by)Split rows into groups for aggregation or transformation.
Built-in aggregations are usually clearer and faster than a custom Python loop.
import pandas as pd
by_region = df.groupby("region")["revenue"].sum()pandas documentation GroupBy.agggrouped.agg(...)Calculate one or more named summaries per group.
Named aggregation gives output columns clear names and makes the result easy to interpret.
import pandas as pd
summary = df.groupby("region", as_index=False).agg(total=("revenue", "sum"))pandas documentation pd.concatpd.concat(objects, axis=0, ignore_index=False)Combine Series or DataFrames along an axis.
Use axis=0 to append rows and axis=1 to align columns. Check indexes and schemas before combining.
import pandas as pd
all_months = pd.concat([january, february], ignore_index=True)pandas documentation pd.mergepd.merge(left, right, on=..., how="inner")Join tables using one or more key columns.
Choose the join type deliberately and validate key uniqueness/cardinality to avoid unexpected row multiplication.
import pandas as pd
orders_with_products = pd.merge(orders, products, on="product_id", how="left")pandas documentation DataFrame.pivot_tabledf.pivot_table(values, index, columns, aggfunc="mean")Reshape records into a summary table with aggregation.
Unlike pivot, pivot_table can aggregate duplicate key combinations. Select an aggregation that matches the question.
import pandas as pd
summary = df.pivot_table(values="revenue", index="region", columns="month", aggfunc="sum")pandas documentation Finished the course? Visit the references and further reading.