0人加入学习
(0人评价)
Python录播课
价格 $99,999美元
该课程属于 商业/数据分析师培养计划(2021年5月) 请加入后再学习

Python 6        Pandas

一. Pandas objects

Panda objects can be thought of as enhanced version of arrays. Similar to excel sheet commonly used by analysis which include rows and column. There are 3 fundamental data structure for pandas:

(1) Series

(2) DataFrame

(3) Index

1. Pandas series (类似于list)

One dimensional array of indexed data, including value of pandas series, index of pandas series, and access data via index.

(1) Unlike regular array and list, pandas series could explicitly define index.

(2) Construct pandas series using dictionary , 即类似于dictionary,可以自定义key和对应的value  

如何将dictionary转换成pandas series?如:

math_dict = {'Scarlet' : 80.0,  'Tony' : 96.0 , 'Thor' : 40.0 ,  'Hulk' : '??'}

math = pd. Series (math_dict)

2. Pandas DataFrame (类似于excel,相当于把多个series加在一起,成multiple dimensional table) (详见google colab)

DataFrame can be thought of either as a generalization of array, or as a specialization of python dictinoary. (例见google colab)

DataFrame is similar to series (also has index) , but unique for DataFrame (has columns).

Similar to dictionary, DataFrame map key to value as well. In this case the key is column name, and value is a series.

3. Reading data from files

(1) reading csv file

如: df = pd. read_csv ( '           .csv') (''内为file name)

(2) set name to be the index

如:   df = df. set_index ('name')

(3) set name to be the index when importing file (在reading csv file时设置名字为index)

如: df = pd. read_csv ('file name', index_col = 0) index_col=0表示以数据里的第一个column作为index

(4) reading from other type of files

如:df = pd. read_json ('        .json')

 

 

 

 

 

 

[展开全文]

授课教师

课程特色

视频(9)

学员动态

horace 加入学习
Sun0422 完成了 Python 6
Sun0422 完成了 Python 7
Sun0422 完成了 Python 8
Sun0422 开始学习 Python 5