DataFrame
Constructor
DataFrame([data, index, columns, dtype, copy]) |
Two-dimensional size-mutable, potentially heterogeneous tabular data structure with labeled axes (rows and columns). |
Attributes and underlying data
Axes
- index: row labels
- columns: column labels
DataFrame.as_matrix([columns]) |
Convert the frame to its Numpy-array representation. |
DataFrame.dtypes |
Return the dtypes in this object. |
DataFrame.ftypes |
Return the ftypes (indication of sparse/dense and dtype) in this object. |
DataFrame.get_dtype_counts() |
Return the counts of dtypes in this object. |
DataFrame.get_ftype_counts() |
Return the counts of ftypes in this object. |
DataFrame.select_dtypes([include, exclude]) |
Return a subset of a DataFrame including/excluding columns based on their dtype. |
DataFrame.values |
Numpy representation of NDFrame |
DataFrame.axes |
Return a list with the row axis labels and column axis labels as the only members. |
DataFrame.ndim |
Number of axes / array dimensions |
DataFrame.size |
number of elements in the NDFrame |
DataFrame.shape |
Return a tuple representing the dimensionality of the DataFrame. |
DataFrame.memory_usage([index, deep]) |
Memory usage of DataFrame columns. |
Conversion
DataFrame.astype(dtype[, copy, raise_on_error]) |
Cast object to input numpy.dtype |
DataFrame.convert_objects([convert_dates, ...]) |
Deprecated. |
DataFrame.copy([deep]) |
Make a copy of this objects data. |
DataFrame.isnull() |
Return a boolean same-sized object indicating if the values are null. |
DataFrame.notnull() |
Return a boolean same-sized object indicating if the values are not null. |
Indexing, iteration
DataFrame.head([n]) |
Returns first n rows |
DataFrame.at |
Fast label-based scalar accessor |
DataFrame.iat |
Fast integer location scalar accessor. |
DataFrame.ix |
A primarily label-location based indexer, with integer position fallback. |
DataFrame.loc |
Purely label-location based indexer for selection by label. |
DataFrame.iloc |
Purely integer-location based indexing for selection by position. |
DataFrame.insert(loc, column, value[, ...]) |
Insert column into DataFrame at specified location. |
DataFrame.__iter__() |
Iterate over infor axis |
DataFrame.iteritems() |
Iterator over (column name, Series) pairs. |
DataFrame.iterrows() |
Iterate over DataFrame rows as (index, Series) pairs. |
DataFrame.itertuples([index, name]) |
Iterate over DataFrame rows as namedtuples, with index value as first element of the tuple. |
DataFrame.lookup(row_labels, col_labels) |
Label-based “fancy indexing” function for DataFrame. |
DataFrame.pop(item) |
Return item and drop from frame. |
DataFrame.tail([n]) |
Returns last n rows |
DataFrame.xs(key[, axis, level, drop_level]) |
Returns a cross-section (row(s) or column(s)) from the Series/DataFrame. |
DataFrame.isin(values) |
Return boolean DataFrame showing whether each element in the DataFrame is contained in values. |
DataFrame.where(cond[, other, inplace, ...]) |
Return an object of same shape as self and whose corresponding entries are from self where cond is True and otherwise are from other. |
DataFrame.mask(cond[, other, inplace, axis, ...]) |
Return an object of same shape as self and whose corresponding entries are from self where cond is False and otherwise are from other. |
DataFrame.query(expr[, inplace]) |
Query the columns of a frame with a boolean expression. |
For more information on .at, .iat, .ix, .loc, and
.iloc, see the indexing documentation.
Binary operator functions
DataFrame.add(other[, axis, level, fill_value]) |
Addition of dataframe and other, element-wise (binary operator add). |
DataFrame.sub(other[, axis, level, fill_value]) |
Subtraction of dataframe and other, element-wise (binary operator sub). |
DataFrame.mul(other[, axis, level, fill_value]) |
Multiplication of dataframe and other, element-wise (binary operator mul). |
DataFrame.div(other[, axis, level, fill_value]) |
Floating division of dataframe and other, element-wise (binary operator truediv). |
DataFrame.truediv(other[, axis, level, ...]) |
Floating division of dataframe and other, element-wise (binary operator truediv). |
DataFrame.floordiv(other[, axis, level, ...]) |
Integer division of dataframe and other, element-wise (binary operator floordiv). |
DataFrame.mod(other[, axis, level, fill_value]) |
Modulo of dataframe and other, element-wise (binary operator mod). |
DataFrame.pow(other[, axis, level, fill_value]) |
Exponential power of dataframe and other, element-wise (binary operator pow). |
DataFrame.radd(other[, axis, level, fill_value]) |
Addition of dataframe and other, element-wise (binary operator radd). |
DataFrame.rsub(other[, axis, level, fill_value]) |
Subtraction of dataframe and other, element-wise (binary operator rsub). |
DataFrame.rmul(other[, axis, level, fill_value]) |
Multiplication of dataframe and other, element-wise (binary operator rmul). |
DataFrame.rdiv(other[, axis, level, fill_value]) |
Floating division of dataframe and other, element-wise (binary operator rtruediv). |
DataFrame.rtruediv(other[, axis, level, ...]) |
Floating division of dataframe and other, element-wise (binary operator rtruediv). |
DataFrame.rfloordiv(other[, axis, level, ...]) |
Integer division of dataframe and other, element-wise (binary operator rfloordiv). |
DataFrame.rmod(other[, axis, level, fill_value]) |
Modulo of dataframe and other, element-wise (binary operator rmod). |
DataFrame.rpow(other[, axis, level, fill_value]) |
Exponential power of dataframe and other, element-wise (binary operator rpow). |
DataFrame.lt(other[, axis, level]) |
Wrapper for flexible comparison methods lt |
DataFrame.gt(other[, axis, level]) |
Wrapper for flexible comparison methods gt |
DataFrame.le(other[, axis, level]) |
Wrapper for flexible comparison methods le |
DataFrame.ge(other[, axis, level]) |
Wrapper for flexible comparison methods ge |
DataFrame.ne(other[, axis, level]) |
Wrapper for flexible comparison methods ne |
DataFrame.eq(other[, axis, level]) |
Wrapper for flexible comparison methods eq |
DataFrame.combine(other, func[, fill_value, ...]) |
Add two DataFrame objects and do not propagate NaN values, so if for a |
DataFrame.combine_first(other) |
Combine two DataFrame objects and default to non-null values in frame calling the method. |
Function application, GroupBy & Window
DataFrame.apply(func[, axis, broadcast, ...]) |
Applies function along input axis of DataFrame. |
DataFrame.applymap(func) |
Apply a function to a DataFrame that is intended to operate elementwise, i.e. |
DataFrame.groupby([by, axis, level, ...]) |
Group series using mapper (dict or key function, apply given function to group, return result as series) or by a series of columns. |
DataFrame.rolling(window[, min_periods, ...]) |
Provides rolling window calculcations. |
DataFrame.expanding([min_periods, freq, ...]) |
Provides expanding transformations. |
DataFrame.ewm([com, span, halflife, alpha, ...]) |
Provides exponential weighted functions |
Computations / Descriptive Stats
DataFrame.abs() |
Return an object with absolute value taken–only applicable to objects that are all numeric. |
DataFrame.all([axis, bool_only, skipna, level]) |
Return whether all elements are True over requested axis |
DataFrame.any([axis, bool_only, skipna, level]) |
Return whether any element is True over requested axis |
DataFrame.clip([lower, upper, axis]) |
Trim values at input threshold(s). |
DataFrame.clip_lower(threshold[, axis]) |
Return copy of the input with values below given value(s) truncated. |
DataFrame.clip_upper(threshold[, axis]) |
Return copy of input with values above given value(s) truncated. |
DataFrame.corr([method, min_periods]) |
Compute pairwise correlation of columns, excluding NA/null values |
DataFrame.corrwith(other[, axis, drop]) |
Compute pairwise correlation between rows or columns of two DataFrame objects. |
DataFrame.count([axis, level, numeric_only]) |
Return Series with number of non-NA/null observations over requested axis. |
DataFrame.cov([min_periods]) |
Compute pairwise covariance of columns, excluding NA/null values |
DataFrame.cummax([axis, skipna]) |
Return cumulative max over requested axis. |
DataFrame.cummin([axis, skipna]) |
Return cumulative minimum over requested axis. |
DataFrame.cumprod([axis, skipna]) |
Return cumulative product over requested axis. |
DataFrame.cumsum([axis, skipna]) |
Return cumulative sum over requested axis. |
DataFrame.describe([percentiles, include, ...]) |
Generate various summary statistics, excluding NaN values. |
DataFrame.diff([periods, axis]) |
1st discrete difference of object |
DataFrame.eval(expr[, inplace]) |
Evaluate an expression in the context of the calling DataFrame instance. |
DataFrame.kurt([axis, skipna, level, ...]) |
Return unbiased kurtosis over requested axis using Fisher’s definition of kurtosis (kurtosis of normal == 0.0). |
DataFrame.mad([axis, skipna, level]) |
Return the mean absolute deviation of the values for the requested axis |
DataFrame.max([axis, skipna, level, ...]) |
This method returns the maximum of the values in the object. |
DataFrame.mean([axis, skipna, level, ...]) |
Return the mean of the values for the requested axis |
DataFrame.median([axis, skipna, level, ...]) |
Return the median of the values for the requested axis |
DataFrame.min([axis, skipna, level, ...]) |
This method returns the minimum of the values in the object. |
DataFrame.mode([axis, numeric_only]) |
Gets the mode(s) of each element along the axis selected. |
DataFrame.pct_change([periods, fill_method, ...]) |
Percent change over given number of periods. |
DataFrame.prod([axis, skipna, level, ...]) |
Return the product of the values for the requested axis |
DataFrame.quantile([q, axis, numeric_only, ...]) |
Return values at the given quantile over requested axis, a la numpy.percentile. |
DataFrame.rank([axis, method, numeric_only, ...]) |
Compute numerical data ranks (1 through n) along axis. |
DataFrame.round([decimals]) |
Round a DataFrame to a variable number of decimal places. |
DataFrame.sem([axis, skipna, level, ddof, ...]) |
Return unbiased standard error of the mean over requested axis. |
DataFrame.skew([axis, skipna, level, ...]) |
Return unbiased skew over requested axis |
DataFrame.sum([axis, skipna, level, ...]) |
Return the sum of the values for the requested axis |
DataFrame.std([axis, skipna, level, ddof, ...]) |
Return sample standard deviation over requested axis. |
DataFrame.var([axis, skipna, level, ddof, ...]) |
Return unbiased variance over requested axis. |
Reindexing / Selection / Label manipulation
DataFrame.add_prefix(prefix) |
Concatenate prefix string with panel items names. |
DataFrame.add_suffix(suffix) |
Concatenate suffix string with panel items names. |
DataFrame.align(other[, join, axis, level, ...]) |
Align two object on their axes with the |
DataFrame.drop(labels[, axis, level, ...]) |
Return new object with labels in requested axis removed. |
DataFrame.drop_duplicates(*args, **kwargs) |
Return DataFrame with duplicate rows removed, optionally only |
DataFrame.duplicated(*args, **kwargs) |
Return boolean Series denoting duplicate rows, optionally only |
DataFrame.equals(other) |
Determines if two NDFrame objects contain the same elements. |
DataFrame.filter([items, like, regex, axis]) |
Subset rows or columns of dataframe according to labels in the specified index. |
DataFrame.first(offset) |
Convenience method for subsetting initial periods of time series data based on a date offset. |
DataFrame.head([n]) |
Returns first n rows |
DataFrame.idxmax([axis, skipna]) |
Return index of first occurrence of maximum over requested axis. |
DataFrame.idxmin([axis, skipna]) |
Return index of first occurrence of minimum over requested axis. |
DataFrame.last(offset) |
Convenience method for subsetting final periods of time series data based on a date offset. |
DataFrame.reindex([index, columns]) |
Conform DataFrame to new index with optional filling logic, placing NA/NaN in locations having no value in the previous index. |
DataFrame.reindex_axis(labels[, axis, ...]) |
Conform input object to new index with optional filling logic, placing NA/NaN in locations having no value in the previous index. |
DataFrame.reindex_like(other[, method, ...]) |
Return an object with matching indices to myself. |
DataFrame.rename([index, columns]) |
Alter axes input function or functions. |
DataFrame.rename_axis(mapper[, axis, copy, ...]) |
Alter index and / or columns using input function or functions. |
DataFrame.reset_index([level, drop, ...]) |
For DataFrame with multi-level index, return new DataFrame with labeling information in the columns under the index names, defaulting to ‘level_0’, ‘level_1’, etc. |
DataFrame.sample([n, frac, replace, ...]) |
Returns a random sample of items from an axis of object. |
DataFrame.select(crit[, axis]) |
Return data corresponding to axis labels matching criteria |
DataFrame.set_index(keys[, drop, append, ...]) |
Set the DataFrame index (row labels) using one or more existing columns. |
DataFrame.tail([n]) |
Returns last n rows |
DataFrame.take(indices[, axis, convert, is_copy]) |
Analogous to ndarray.take |
DataFrame.truncate([before, after, axis, copy]) |
Truncates a sorted NDFrame before and/or after some particular index value. |
Missing data handling
DataFrame.dropna([axis, how, thresh, ...]) |
Return object with labels on given axis omitted where alternately any |
DataFrame.fillna([value, method, axis, ...]) |
Fill NA/NaN values using the specified method |
DataFrame.replace([to_replace, value, ...]) |
Replace values given in ‘to_replace’ with ‘value’. |
Reshaping, sorting, transposing
DataFrame.pivot([index, columns, values]) |
Reshape data (produce a “pivot” table) based on column values. |
DataFrame.reorder_levels(order[, axis]) |
Rearrange index levels using input order. |
DataFrame.sort_values(by[, axis, ascending, ...]) |
Sort by the values along either axis |
DataFrame.sort_index([axis, level, ...]) |
Sort object by labels (along an axis) |
DataFrame.sortlevel([level, axis, ...]) |
Sort multilevel index by chosen axis and primary level. |
DataFrame.nlargest(n, columns[, keep]) |
Get the rows of a DataFrame sorted by the n largest values of columns. |
DataFrame.nsmallest(n, columns[, keep]) |
Get the rows of a DataFrame sorted by the n smallest values of columns. |
DataFrame.swaplevel([i, j, axis]) |
Swap levels i and j in a MultiIndex on a particular axis |
DataFrame.stack([level, dropna]) |
Pivot a level of the (possibly hierarchical) column labels, returning a DataFrame (or Series in the case of an object with a single level of column labels) having a hierarchical index with a new inner-most level of row labels. |
DataFrame.unstack([level, fill_value]) |
Pivot a level of the (necessarily hierarchical) index labels, returning a DataFrame having a new level of column labels whose inner-most level consists of the pivoted index labels. |
DataFrame.T |
Transpose index and columns |
DataFrame.to_panel() |
Transform long (stacked) format (DataFrame) into wide (3D, Panel) format. |
DataFrame.to_xarray() |
Return an xarray object from the pandas object. |
DataFrame.transpose(*args, **kwargs) |
Transpose index and columns |
Combining / joining / merging
DataFrame.append(other[, ignore_index, ...]) |
Append rows of other to the end of this frame, returning a new object. |
DataFrame.assign(**kwargs) |
Assign new columns to a DataFrame, returning a new object (a copy) with all the original columns in addition to the new ones. |
DataFrame.join(other[, on, how, lsuffix, ...]) |
Join columns with other DataFrame either on index or on a key column. |
DataFrame.merge(right[, how, on, left_on, ...]) |
Merge DataFrame objects by performing a database-style join operation by columns or indexes. |
DataFrame.update(other[, join, overwrite, ...]) |
Modify DataFrame in place using non-NA values from passed DataFrame. |
Plotting
DataFrame.plot is both a callable method and a namespace attribute for
specific plotting methods of the form DataFrame.plot.<kind>.
DataFrame.plot([x, y, kind, ax, ....]) |
DataFrame plotting accessor and method |
DataFrame.plot.area([x, y]) |
Area plot |
DataFrame.plot.bar([x, y]) |
Vertical bar plot |
DataFrame.plot.barh([x, y]) |
Horizontal bar plot |
DataFrame.plot.box([by]) |
Boxplot |
DataFrame.plot.density(**kwds) |
Kernel Density Estimate plot |
DataFrame.plot.hexbin(x, y[, C, ...]) |
Hexbin plot |
DataFrame.plot.hist([by, bins]) |
Histogram |
DataFrame.plot.kde(**kwds) |
Kernel Density Estimate plot |
DataFrame.plot.line([x, y]) |
Line plot |
DataFrame.plot.pie([y]) |
Pie chart |
DataFrame.plot.scatter(x, y[, s, c]) |
Scatter plot |
DataFrame.boxplot([column, by, ax, ...]) |
Make a box plot from DataFrame column optionally grouped by some columns or |
DataFrame.hist(data[, column, by, grid, ...]) |
Draw histogram of the DataFrame’s series using matplotlib / pylab. |
Serialization / IO / Conversion
DataFrame.from_csv(path[, header, sep, ...]) |
Read CSV file (DISCOURAGED, please use pandas.read_csv() instead). |
DataFrame.from_dict(data[, orient, dtype]) |
Construct DataFrame from dict of array-like or dicts |
DataFrame.from_items(items[, columns, orient]) |
Convert (key, value) pairs to DataFrame. |
DataFrame.from_records(data[, index, ...]) |
Convert structured or record ndarray to DataFrame |
DataFrame.info([verbose, buf, max_cols, ...]) |
Concise summary of a DataFrame. |
DataFrame.to_pickle(path) |
Pickle (serialize) object to input file path. |
DataFrame.to_csv([path_or_buf, sep, na_rep, ...]) |
Write DataFrame to a comma-separated values (csv) file |
DataFrame.to_hdf(path_or_buf, key, **kwargs) |
Activate the HDFStore. |
DataFrame.to_sql(name, con[, flavor, ...]) |
Write records stored in a DataFrame to a SQL database. |
DataFrame.to_dict([orient]) |
Convert DataFrame to dictionary. |
DataFrame.to_excel(excel_writer[, ...]) |
Write DataFrame to a excel sheet |
DataFrame.to_json([path_or_buf, orient, ...]) |
Convert the object to a JSON string. |
DataFrame.to_html([buf, columns, col_space, ...]) |
Render a DataFrame as an HTML table. |
DataFrame.to_latex([buf, columns, ...]) |
Render a DataFrame to a tabular environment table. |
DataFrame.to_stata(fname[, convert_dates, ...]) |
A class for writing Stata binary dta files from array-like objects |
DataFrame.to_msgpack([path_or_buf, encoding]) |
msgpack (serialize) object to input file path |
DataFrame.to_gbq(destination_table, project_id) |
Write a DataFrame to a Google BigQuery table. |
DataFrame.to_records([index, convert_datetime64]) |
Convert DataFrame to record array. |
DataFrame.to_sparse([fill_value, kind]) |
Convert to SparseDataFrame |
DataFrame.to_dense() |
Return dense representation of NDFrame (as opposed to sparse) |
DataFrame.to_string([buf, columns, ...]) |
Render a DataFrame to a console-friendly tabular output. |
DataFrame.to_clipboard([excel, sep]) |
Attempt to write text representation of object to the system clipboard This can be pasted into Excel, for example. |