pandas 1.4.2

ParametersBackRef

Data structure also contains labeled axes (rows and columns). Arithmetic operations align on both row and column labels. Can be thought of as a dict-like container for Series objects. The primary pandas data structure.

Parameters

data : ndarray (structured or homogeneous), Iterable, dict, or DataFrame

Dict can contain Series, arrays, constants, dataclass or list-like objects. If data is a dict, column order follows insertion-order. If a dict contains Series which have an index defined, it is aligned by its index.

versionchanged

If data is a list of dicts, column order follows insertion-order.

index : Index or array-like

Index to use for resulting frame. Will default to RangeIndex if no indexing information part of input data and no index provided.

columns : Index or array-like

Column labels to use for resulting frame when data does not have them, defaulting to RangeIndex(0, 1, 2, ..., n). If data contains column labels, will perform column selection instead.

dtype : dtype, default None

Data type to force. Only a single dtype is allowed. If None, infer.

copy : bool or None, default None

Copy data from inputs. For dict data, the default of None behaves like copy=True . For DataFrame or 2d ndarray input, the default of None behaves like copy=False .

versionchanged

Two-dimensional, size-mutable, potentially heterogeneous tabular data.

See Also

DataFrame.from_dict

From dicts of Series, arrays, or dicts.

DataFrame.from_records

Constructor from tuples, also record arrays.

read_clipboard

Read text from clipboard into DataFrame.

read_csv

Read a comma-separated values (csv) file into DataFrame.

read_table

Read general delimited file into DataFrame.

Examples

Constructing DataFrame from a dictionary.

This example is valid syntax, but we were not able to check execution
>>> d = {'col1': [1, 2], 'col2': [3, 4]}
... df = pd.DataFrame(data=d)
... df col1 col2 0 1 3 1 2 4

Notice that the inferred dtype is int64.

This example is valid syntax, but we were not able to check execution
>>> df.dtypes
col1    int64
col2    int64
dtype: object

To enforce a single dtype:

This example is valid syntax, but we were not able to check execution
>>> df = pd.DataFrame(data=d, dtype=np.int8)
... df.dtypes col1 int8 col2 int8 dtype: object

Constructing DataFrame from a dictionary including Series:

This example is valid syntax, but we were not able to check execution
>>> d = {'col1': [0, 1, 2, 3], 'col2': pd.Series([2, 3], index=[2, 3])}
... pd.DataFrame(data=d, index=[0, 1, 2, 3]) col1 col2 0 0 NaN 1 1 NaN 2 2 2.0 3 3 3.0

Constructing DataFrame from numpy ndarray:

This example is valid syntax, but we were not able to check execution
>>> df2 = pd.DataFrame(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]),
...  columns=['a', 'b', 'c'])
... df2 a b c 0 1 2 3 1 4 5 6 2 7 8 9

Constructing DataFrame from a numpy ndarray that has labeled columns:

This example is valid syntax, but we were not able to check execution
>>> data = np.array([(1, 2, 3), (4, 5, 6), (7, 8, 9)],
...  dtype=[("a", "i4"), ("b", "i4"), ("c", "i4")])
... df3 = pd.DataFrame(data, columns=['c', 'a']) ...
This example is valid syntax, but we were not able to check execution
>>> df3
   c  a
0  3  1
1  6  4
2  9  7

Constructing DataFrame from dataclass:

This example is valid syntax, but we were not able to check execution
>>> from dataclasses import make_dataclass
... Point = make_dataclass("Point", [("x", int), ("y", int)])
... pd.DataFrame([Point(0, 0), Point(0, 3), Point(2, 3)]) x y 0 0 0 1 0 3 2 2 3
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

skimage.measure._regionprops.regionprops_table pandas.core.frame.DataFrame.join pandas.plotting pandas.core.indexes.multi.MultiIndex.to_frame pandas.core.frame.DataFrame.count pandas pandas.plotting._misc.radviz networkx.convert_matrix.from_pandas_edgelist pandas.io.formats.format.get_dataframe_repr_params matplotlib.pyplot.plot skimage.measure._regionprops._props_to_dict matplotlib.axes._axes.Axes.plot pandas.io.excel._base.read_excel networkx.convert_matrix.to_pandas_edgelist networkx.convert_matrix.from_pandas_adjacency

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/frame.py#459
type: <class 'type'>
Commit: