Pandas
Python“玩”数据的利器!
Series
Series是一个能够容纳任意数据类型的带标记的一维数组。(Series is a one-dimensional labeled array capable of holding any data type (integers, strings, floating point numbers, Python objects, etc.). The axis labels are collectively referred to as the index. )
初始化
1 | import numpy as np |
转化为list
1 | s.tolist() |
Dataframe
可以将DataFrame看做是一个表格。(DataFrame is a 2-dimensional labeled data structure with columns of potentially different types. You can think of it like a spreadsheet or SQL table, or a dict of Series objects. It is generally the most commonly used pandas object.)
初始化
1 | import pandas as pd |
IO操作
1 | df = pd.read_csv('') # 读取csv文件 |
列操作
对每列进行操作(apply)
1 | df.apply(lambda x: x.max() - x.min()) |
某列取值分布
1 | d = {'one': [1.0, 2.0, 3.0, 4.0], 'two': [4.0, 3.0, 2.0, 1.0]} |
行操作
遍历行
1 | for index, row in df.iterrows(): |
评论系统未开启,无法评论!