Pandas data analysis (data structure) and pandas Data Analysis

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.