Pandas data analysis (data structure) and pandas Data Analysis
This article mainly expands pandas data structures in the following two directions: Series and DataFrame (corresponding to one-dimensional arrays and two-dimensional arrays in Series and numpy)
1. First, we will introduce how to create a Series.
1) A sequence can be created using an array.
For example, test in python3.6.
# First, import two modules,
Import numpy as np
Import pandas as pd
# Create the first sequence
Array1 = np. arange (10)
Print (array1)
Print (type (array1 ))
#[0 1 2 3 4 5 6 7 8 9]
# <Class 'numpy. ndarray'>
S1 = pd. Series (array1)
Print (s1)
Print (type (s1 ))
Through the above, you can easily create a Series
As follows:
####
0 0
1 1
2 2
3 3
4
5 5
6 6
7
8
9 9
Dtype: int32
#######
The first column is the index column of Series, and the second column is an array from 0 to 9.
Dtype is the data type of Series (we will introduce the Data Type in pandas later)
2) We can also create Series in the form of dictionaries.
Dict1 = {'A': 10, 'B': 20, 'C': 30, 'D': 40, 'E': 50}
S2 = pd. Series (dict1)
Print (s2)
####
A 10
B 20
C 30
D 40
E 50
Dtype: int64
####
After the dictionary is passed into Series, the dictionary's key-value pairs are converted into index columns and data columns of Series respectively.