Pandas入门

花式索引

我们的主要数据结构就是DataFrame了,DataFrame有两部分构成,一个是列(columns)。列是有名称的或者说有标签的(图中:AREACD等)。另一个是索引(index),这里我们为了避孕歧义称之为行(rows),行一般没有名称(图中1到8),但是也可以有名称。

 

 

import pandas as pd
import numpy as np

data = {'animal': ['cat', 'cat', 'snake', 'dog', 'dog', 'cat', 'snake', 'cat', 'dog', 'dog'],
        'age': [2.5, 3, 0.5, np.nan, 5, 2, 4.5, np.nan, 7, 3],
        'visits': [1, 3, 2, 3, 2, 3, 1, 1, 2, 1],
        'priority': ['yes', 'yes', 'no', 'yes', 'no', 'no', 'no', 'yes', 'no', 'no']}

labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']

df = pd.DataFrame(data, index=labels)
View Code

 Spyder执行后:

 

 

 

 

 

posted @ 2020-04-24 15:49  有翅膀的大象  阅读(172)  评论(0编辑  收藏  举报