Introduction to PYTHON Pandas Data Structures

Original article was published on Artificial Intelligence on Medium

PYTHON Pandas Series

The series is a one-dimensional tagged array that can hold any type of data (integer, string, float, python objects, etc.). Axis labels are collectively called directories.

A pandas Series can be created using the following builder:

pandas.Series( data, index, dtype, copy)

The founder’s parameters are as follows: data: data takes various forms such as ndarray, list, constant

  • Index: Index values ​​must be unique and hashable, with the same length as the data.
  • dtype: for the dtype data type. If not, the data type will be removed.
  • copy: copies the data. the default value is false.

It can be created using several inputs, such as a series:

  • Array
  • Dict
  • Scalar value and constant

Creating an Empty Series

A basic array that can be created is an empty series.

Series([], dtype: float64)

Creating a Series with ndarray

If the data is a ndarray, the passed directory must be of the same length. By default, the index takes the range where n is the array length, rather than the index of the same length. That is: (n) [0,1,2,3 …. Range (len (series)) — 1].

Example 1:

0 a
1 b
2 c
3 d
dtype: object

Example 2:

10 a
20 b
30 c
40 d
dtype: object

We passed the index values ​​here. Now you can see the output customized index values.

Creating Series with Dict

A dict can be passed as input, and if the index is not specified, dictionary keys are imported in a sequential order to create the index. If the index is passed, the values ​​in the data corresponding to the labels in the index are pulled out.

Example 1:

a 0.0
b 1.0
c 2.0
dtype: float64

Example 2:

zero 0.0
one 1.0
two NaN
three 3.0
dtype: float64

Creating a Series with Scalar

If the data is a scalar value, a directory must be provided. The value is repeated to match the index length.

0 5
1 5
2 5
3 5
dtype: int64