Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

API reference

Pandas API reference

Pandas DataFrames and data manipulation

Identifiers
129
With full guides
115
Types
5

Topics covered

  • Series & DataFrame
  • Reading data
  • Selection (loc/iloc)
  • Filtering
  • GroupBy
  • Merging & joining
  • Missing data
  • Pivot & reshape

Class

NameWhat it does
DataFrameA DataFrame is pandas’ mutable, two-dimensional table with labeled rows and columns. Its columns can hold different data types, and arithmetic aligns values by both axis labels.
Seriespandas.Series is a one-dimensional labeled data structure that supports positional and label-based indexing. Arithmetic aligns operands by their index labels.
Indexpandas.Index is an immutable sequence of labels used for indexing and alignment. It is the core axis-label object used by pandas Series and DataFrame objects.
MultiIndexpandas.MultiIndex is a hierarchical index that uses multiple levels of labels on one Series or DataFrame axis. It supports indexing by combinations of keys while keeping the underlying object at its usual dimensionality.

Function

NameWhat it does
read_csvFunction
read_jsonReads JSON text, files, URLs, or file-like objects into a pandas Series or DataFrame. It also supports line-delimited and compressed JSON, with chunksize enabling batch iteration.
pd.concatFunction
pd.mergeFunction
groupbyFunction
pivot_tableCreates a spreadsheet-style pivot table from a DataFrame by grouping row and column keys and aggregating selected values. It supports custom aggregation, missing-value filling, totals, categorical-group control, and sorting.
df.applyApply a callable independently along each DataFrame column or row. The default passes labeled Series objects and infers the result shape from the callable; options support ndarray inputs and explicit row-wise list-result handling.
df.fillnaReplaces missing values in a DataFrame with a scalar or aligned, column-specific values. It returns a filled copy by default, or can modify the original in place.
df.dropnaDataFrame.dropna removes rows or columns containing missing values. Configure the axis, removal rule, minimum non-missing count, inspected labels, mutation behavior, and resulting index.
df.to_csvWrites a DataFrame to a comma-separated values file or returns the CSV text. By default, it includes column headers and the row index.
df.describeDataFrame.describe generates descriptive statistics for analyzed columns, excluding NaN values. It can summarize mixed-type DataFrames and filter analyzed columns with include or exclude.
df.sort_valuesFunction
df.value_countsCounts distinct row combinations in a DataFrame and returns them as a Series. You can restrict the counted columns, request proportions, control ordering, and include missing-value rows.
pd.to_datetimeConverts scalar, array-like, Series, or DataFrame/dict-like input into pandas datetime objects. Options control error handling, parsing formats, timezone normalization, numeric units, origin, and caching.
df.headReturns the first rows of a DataFrame by position. It defaults to five rows and supports positive, zero, and negative counts.
df.groupbyGroups a DataFrame by labels, mappings, functions, pd.Grouper objects, or index levels. It returns a groupby object for later aggregation, transformation, or other group-wise operations.
pd.read_csvFunction
pd.read_excelReads supported Excel or OpenDocument spreadsheet files into a DataFrame, from a local path, URL, bytes-like input, or file-like object. It can read one sheet or multiple sheets and offers controls for columns, types, missing values, dates, and parsing.
pd.read_jsonFunction
pd.read_sqlFunction
pd.read_parquetReads a Parquet object into a pandas DataFrame. It supports column selection, engine and storage configuration, dtype backends, and optional row filtering.
pd.read_htmlReads HTML tables from a URL, path, file-like object, or HTML string and returns a list of pandas DataFrames. Tables can be selected by matching text or HTML attributes.
pd.read_pickleLoads a pickled pandas object—or any other pickled object—from a file, URL, or binary stream. It can infer or apply compression and accepts storage-specific connection options.
pd.read_featherLoads a Feather-format file or file-like object into a pandas DataFrame. It supports column selection, threaded reading, storage options, and configurable dtype backends.
pd.read_clipboardFunction
pd.get_dummiesConverts categorical values into 0/1 indicator columns. DataFrame inputs can selectively encode columns and retain other columns.
pd.cutFunction
pd.qcutDivides one-dimensional data into quantile-based buckets, typically producing groups with similar numbers of observations. Use q to choose a number of quantiles or provide explicit quantile probabilities.
pd.pivot_tableCreate a spreadsheet-style pivot table from a DataFrame by grouping row and column keys and aggregating selected values. The result is a DataFrame whose axes may be hierarchical.
pd.crosstabpandas.crosstab computes a cross-tabulation of two or more factors. It produces frequency counts by default, or aggregates supplied values when paired with aggfunc.
pd.date_rangepd.date_range creates a fixed-frequency DatetimeIndex from date bounds, a period count, or both. Specify exactly three of start, end, periods, and freq; inclusive controls boundary inclusion.
pd.to_numericConverts scalar or sequence-like input to numeric data. Invalid values raise by default or can be converted to missing values with coercion; downcast and dtype_backend provide output-type control.
pd.factorizepandas.factorize encodes a one-dimensional sequence as integer codes and returns the corresponding unique values. By default, missing values receive -1 and are omitted from uniques.
pd.meltpandas.melt reshapes a DataFrame from wide to long format. It preserves selected identifier columns and unpivots measured columns into variable and value columns.
pd.json_normalizeFunction
pd.read_sql_queryReads a SQL query result into a pandas DataFrame, optionally selecting an index, parsing dates, setting dtypes, or streaming rows in chunks. It accepts SQL text or a SQLAlchemy Selectable and can return a DataFrame iterator when chunksize is set.
pd.read_tableReads a general delimited text file or file-like object into a pandas DataFrame, using tab separation by default. It can also expose incremental chunked parsing for large inputs.
pd.read_xmlReads XML from a path, URL, string, or file-like object into a DataFrame. XPath selects the element collection used for rows, while child elements and attributes become columns.
pd.Timestamppandas.Timestamp is pandas’ scalar datetime type and a replacement for Python’s datetime.datetime. Construct it from datetime-like values, strings, numeric epoch values, or individual date-time components.
pd.Timedeltapd.Timedelta creates a scalar duration from duration-like values, strings, integers with units, or named time components. It is pandas' duration type and interoperates with Python's datetime.timedelta.
pd.Periodpd.Period represents a defined span of time—such as a month, quarter, or year—rather than a single instant. Its freq determines the period's granularity and interpretation.
pd.Categoricalpd.Categorical constructs a categorical array from values, with optional explicit categories and ordering. Explicit categories define permitted values; out-of-category inputs become missing.
pd.isnaDetect whether a scalar or array-like object contains missing values. Scalars return one boolean, while array-like inputs return corresponding boolean indicators.
pd.notnaDetect whether a scalar or array-like object contains non-missing values. The result is a scalar Boolean for scalar input and a corresponding Boolean structure for array-like input.
pd.merge_asofMerges ordered DataFrames by key distance rather than exact equality, retaining every left row. It supports backward, forward, and nearest matching, optional tolerances, and group-wise matching.
pd.wide_to_longUnpivot a DataFrame whose measured columns share stub prefixes and suffixes. Identifier columns become part of the resulting index, while the extracted suffix is named by j.

Const

NameWhat it does
df.locDataFrame.loc selects and assigns DataFrame rows and columns by label, with optional boolean-array filtering. Label slices include both endpoints, and numeric keys remain labels rather than positions.
df.ilocDataFrame.iloc selects rows and columns by zero-based integer position. It supports scalar, list-like, slice, boolean, callable, and row-column tuple indexers.

Module

NameWhat it does
df.atDataFrame.at reads or writes one cell using a row-label and column-label pair. It is the label-based scalar counterpart to positional iat.
df.iatDataFrame.iat reads or writes one cell using integer row and column positions. It is the scalar counterpart to broader positional selection with iloc.
df.tailReturns the last rows of a DataFrame by positional order. It selects five rows by default and supports positive or negative values of n.
df.sampleRandomly selects rows or columns from a DataFrame by count or fraction. Sampling can be weighted, repeated, made reproducible, and returned with a reset index.
df.queryFilters a DataFrame using a boolean expression written as a string. The expression can use DataFrame columns and configurable evaluation context, parser, and engine settings.
df.filterDataFrame.filter selects rows or columns by their labels using exact names, substring matching, or regular expressions. It does not inspect the values in the DataFrame.
df.whereModule
df.maskDataFrame.mask replaces values where a condition is True and keeps values where it is False. Replacement values come from other, or from dtype-appropriate nulls when other is omitted.
df.isinReturns a boolean DataFrame indicating whether each cell's value is present in the supplied iterable, Series, DataFrame, or dictionary. Input type determines whether matching is global, column-specific, or label-aligned.
df.nlargestReturns the rows with the largest values in specified DataFrame columns, ordered descending. It supports configurable handling of ties through keep.
df.nsmallestReturns the first n DataFrame rows with the smallest values in one or more columns, ordered ascending. Other columns are included but do not influence ranking.
df.applymapDataFrame.applymap applies a scalar-to-scalar callable to every DataFrame element and returns a transformed DataFrame. It is deprecated; use DataFrame.map instead.
df.assignDataFrame.assign creates or replaces columns and returns a new DataFrame containing the original columns plus the results. Values may be direct data or callables evaluated against the DataFrame.
df.aggDataFrame.agg applies one or more aggregation operations over a selected axis. It supports single operations, lists of operations, per-column dictionaries, and named aggregations.
df.transformDataFrame.transform applies a function along columns or rows and returns transformed data while preserving the DataFrame’s axis shape. It supports callables, function names, lists, and label-based mappings.
df.pivotReshapes a DataFrame into a matrix using selected fields for its index, columns, and values. It does not aggregate duplicate index-column combinations.
df.stackReshapes a DataFrame by moving selected column levels into the index. The result is a Series for single-level columns or a DataFrame when remaining column levels exist.
df.unstackReshapes selected index levels into columns. MultiIndex inputs produce a DataFrame; a regular index produces a Series.
df.mergeCombines a DataFrame with another DataFrame or named Series using a database-style join. It matches column and/or index keys and supports inner, outer, left, right, cross, and anti-join strategies.
df.joinModule
df.sort_indexModule
df.rankDataFrame.rank assigns numerical ranks along columns by default or across rows when requested. It supports configurable tie, missing-value, direction, numeric-column, and percentile behavior.
df.renameRename a DataFrame’s column labels, index labels, or both with mappings or callables. Unmentioned labels stay unchanged by default, and the operation returns a new DataFrame unless inplace=True.
df.dropDataFrame.drop removes selected labels from rows or columns. Use index= or columns= for readable, axis-free calls; it returns a new DataFrame unless inplace=True.
df.drop_duplicatesRemove duplicate rows from a DataFrame, optionally judging duplicates by selected columns. Choose whether to keep the first, last, or none of each duplicate group, and optionally reset the result index.
df.replaceReplaces matching values in a DataFrame with specified alternatives. It supports scalar, list, dictionary, and regular-expression-based replacements, and returns a new frame unless inplace=True.
df.astypeDataFrame.astype casts an entire DataFrame to one dtype or applies dtypes column by column through a mapping. Invalid conversions raise by default, with errors='ignore' available to suppress them.
df.roundRounds numeric DataFrame columns to a chosen precision. Use an integer for uniform precision or a dict/Series for per-column precision.
df.clipDataFrame.clip constrains values to optional lower and upper thresholds, replacing out-of-range entries with the relevant boundary. Scalar or array-like thresholds are supported.
df.cumsumComputes cumulative sums along a DataFrame axis, returning an equally sized result. By default it accumulates down columns, skips missing values, and can optionally restrict the operation to numeric columns.
df.rollingCreates sliding windows over a DataFrame for moving calculations. Configure the window, required observations, label placement, weighting, timing column, evaluation spacing, and execution mode before applying an aggregation or transformation.
df.resampleDataFrame.resample groups time-series data into frequency-based bins for frequency conversion or aggregation. Use a datetime-like index, or identify a datetime-like column or level with on or level.
df.shiftDataFrame.shift moves values by a chosen number of periods, inserting missing values where needed. With freq, it advances date-like index labels without realigning the data.
df.diffComputes discrete differences between DataFrame elements, comparing with the previous row by default. Use periods to control the shift and axis to choose rows or columns.
df.pct_changeReturns the fractional change between current and prior DataFrame values. By default it compares adjacent rows; multiply the result by 100 to express the change as a percentage.
df.explodeExpands list-like values in one or more DataFrame columns into separate rows. Non-exploded columns are repeated, and the original index is retained unless you request a fresh one.
df.to_excelWrites a DataFrame to an Excel worksheet. It supports direct file output or coordinated multi-sheet workbooks through ExcelWriter.
df.to_jsonSerializes a DataFrame to JSON text or writes it to a specified destination. Orientation, date encoding, precision, index handling, line output, compression, and formatting are configurable.
df.to_sqlWrites DataFrame records to a SQL database, creating, appending to, or replacing a table. It can control index storage, batching, column types, and insertion strategy.
df.to_parquetWrites a DataFrame in binary Parquet format, using an automatic or explicitly selected backend. It supports compression, index control, dataset partitioning, and filesystem-related options.
df.to_dictConverts a DataFrame into a dictionary-like structure whose shape is selected with orient. It can also use a custom mapping class and optionally omit index metadata for split or tight output.
df.to_numpyDataFrame.to_numpy converts a DataFrame’s values into a NumPy array without its index or column labels. It chooses a common dtype by default, while dtype, copy, and na_value provide explicit control.
df.infoPrint a concise diagnostic summary of a pandas DataFrame, including its index, columns, dtypes, non-null counts, and memory usage. Output is written to standard output unless redirected.
df.dtypesDataFrame.dtypes is a property that returns a Series describing the dtype of every column. The Series uses the DataFrame’s column labels as its index.
df.isnullDetect missing values in a DataFrame by returning a same-sized boolean mask. Missing entries are True, while other entries are False; isnull() is an alias for isna().
df.notnullDetects which DataFrame elements are non-missing. It returns a same-sized boolean DataFrame, with True for present values and False for recognized NA values.
df.nuniqueDataFrame.nunique counts distinct values along an axis and returns a Series. It excludes NaN by default, and can count per row with axis=1 or include missing values with dropna=False.
df.corrComputes pairwise column correlations while excluding missing values. Supports Pearson, Kendall, Spearman, and custom callable methods.
df.covComputes pairwise covariance among DataFrame columns and returns the results as a covariance matrix. Missing values are excluded, and min_periods can require a minimum number of observations per pair.
df.memory_usageReturns per-column memory usage in bytes, optionally including the index and deeper accounting for object-dtype values. DataFrame.info uses this measurement by default.
df.duplicatedReturns a boolean Series identifying duplicate DataFrame rows. Compare all columns by default, or specify subset columns and choose whether to preserve the first, last, or none of each duplicate group.
df.iterrowsIterate over DataFrame rows as index-and-Series pairs. Each row is exposed as a Series, so its values may not retain the original column dtypes; itertuples() is generally faster and preserves types better.
df.itertuplesIterate through DataFrame rows as namedtuples, optionally including the index and choosing a custom tuple type name. Set name=None for ordinary tuples.
df.evalDataFrame.eval evaluates a string expression against DataFrame columns. It can compute results or assign derived columns, optionally mutating the original DataFrame.
df.copyCreates a new DataFrame from the caller’s data and indices. By default it copies them; deep=False creates a shallow copy, with Copy-on-Write protecting writes from affecting the other object.
df.set_indexSets DataFrame row labels from one or more existing columns or same-length arrays. It can replace the current index or add levels to it.
df.reset_indexResets a DataFrame's index to the default integer index. By default, the former index is retained as column data, but it can instead be discarded or selectively reset for a MultiIndex.
df.reindexReindex a DataFrame to specified row and/or column labels, optionally filling newly introduced gaps. Missing labels become NaN by default or receive a supplied fill value.
df.combine_firstFills missing values in one DataFrame from corresponding non-missing values in another. The result uses the union of both DataFrames’ row and column indexes, while the first DataFrame takes precedence where both contain values.
df.updateDataFrame.update mutates a DataFrame with aligned, non-missing values from another object. It preserves the target’s shape and can either overwrite populated cells or fill only missing ones.
df.squeezeRemove DataFrame axes of length one. Depending on the shape and selected axis, the result is a DataFrame, Series, or scalar.
df.idxmaxReturns the label of the first maximum in each column or row of a DataFrame. Missing values are skipped by default, and the axis, missing-value handling, and numeric-column selection are configurable.
df.idxminDataFrame.idxmin returns the label of the first minimum in each column or row. It skips missing values by default and can restrict processing to numeric columns.
df.cummaxReturns the cumulative maximum along a DataFrame or Series axis. By default, it scans each column downward while preserving the input shape.
df.cumminReturns the cumulative minimum along a DataFrame axis, preserving the input shape. By default it operates down columns, skips missing values, and can optionally restrict processing to numeric and Boolean columns.
df.expandingCreates an expanding-window object for a DataFrame. Each subsequent position can aggregate all data available from the beginning through that position.
df.ewmCreates an exponentially weighted window for DataFrame calculations. Supply a decay definition and then apply an operation such as mean() or std().
df.interpolateFill missing DataFrame values by interpolation along an axis. The method supports controls for interpolation strategy, gap size, direction, region, and in-place updates.
df.bfillDataFrame.bfill fills missing values by propagating the next valid observation backward along an axis. It can limit the number and position of values filled, or modify the DataFrame in place.
df.ffillDataFrame.ffill fills missing values by carrying the preceding valid observation forward along an axis. Optional limits control how many values or which regions are filled.

Pipe

NameWhat it does
df.shapeDataFrame.shape returns a tuple containing the number of rows and columns in that order. Read it as (nrows, ncolumns) without calling it.
df.columnsDataFrame.columns gives access to a DataFrame’s column labels as a pandas Index. Read it to inspect labels and assign a new label sequence to rename the columns.
df.indexDataFrame.index is the DataFrame’s row-label index. Read it to inspect labels or assign a replacement sequence to change them.
df.valuesDataFrame.values exposes a DataFrame's cell data as a NumPy array without index or column labels. Prefer DataFrame.to_numpy() for new code.
str accessorPandas' .str accessor supplies vectorized string operations for Series and Index objects, including DataFrame columns and labels. Use it for tasks such as trimming, changing case, matching patterns, splitting, extracting, and concatenating text.
dt accessorSeries.dt is pandas’ dtype-specific accessor for datetime, timedelta, and period values. It provides vectorized date-related properties and methods such as extracting month, year, or weekday information.
cat accessorSeries.cat provides access to categorical properties and operations. In a DataFrame workflow, select a categorical column and use .cat on the resulting Series.

Search across every package and filter by type in your dashboard.

Start learning