找回密码
 立即注册
搜索

Python数据分析系列文章之Pandas(上)

本篇是【机器学习与数据发掘】头条号原创首发Python数据分析系列文章的第三篇

本章引见python数据分析中比较次要的一个库pandas的运用,pandas篇分上下两部分,本节次要引见pandas运用中一些比较重要的操作。

本节目录:
    基本数据结构基本功能数据读存与文件格式总结
基本数据结构

想要纯熟的运用pandas,就需求了解pandas中两种重要的数据结构:Series和DataFrame。
import pandas as pd

Series

1、创建
pd.Series(data=None, index=None, dtype=None, name=None, copy=False, fastpath=False)




Series一种相似于一维数组的数据对象,由一组数据和一组与之对应的索引组成。series创建方式有四种:
    运用Python列表创建运用numpy数组创建运用Python字典创建运用单个标量值创建
#左边为索引,左边为值,没有设置索引,则自动创建0-n的整数序列
s1 = pd.Series(np.array([1,2,3,4,5,np.nan]))
s2 = pd.Series([1,2,3,4,5])
s3 = pd.Series({'a':1,'b':2,'c':3,'d':4})
s4 = pd.Series(3)
#可以自带索引值
s5 = pd.Series([1,2,3,4,5],index=list('abcde'))

2、性质

下面次要引见Series运用中一些常见的方法
#属性
s1.index
#RangeIndex(start=0, stop=5, step=1)
#值
s1.values
#array([1, 2, 3, 4, 5]) #一维数组
s1.value_counts(dropna=True) #值统计,往常用的比较多
s1.notnull()
s1.isnull() #前往元素能否缺失
s1.fillna(0) #缺失值填充
s1.drop_duplicates() #去重
s1.apply(lambda x:x+1) #用的比较多的性质
s2.astype('int') #假如外面有一些不能转为该类型的元素值(如NA,'a')就会出错。
s2.iat[0] #取第一个元素,不是按照index
s2.dtypes #dtype('int64'),类型
s2.nunique() #5,Series中的元素个数,没有反复的
#修正index
index = ['a1','b1','c1','d1','e1']
s5 = pd.Series(dict(s3),index=index)
s5
#a1 1.0
b1 2.0
c1 3.0
d1 4.0
e1 NaN
dtype: float64

3、取值与运算
###取值####
s1[2] #经过index取数据
s3.iat[2] #经过index的顺序取
s1[s1>=3] #取出Series中大于等于3的子集,前往的还是Series
s1[s1.isnull()==True] #去元素为空缺值的子Series
###运算###
s2**2
#0 2
1 4
2 6
3 8
4 10
dtype: int64
s2+s2 #输入同上
np.exp(s2)
#0 2.718282
1 7.389056
2 20.085537
3 54.598150
4 148.413159
dtype: float64

DataFreme

1、创建

DataFrame是一种表格型的数据结构,它含有一组有序的列,每一列元素值类型可以是数值型、类别型、布尔类型,有行和列索引,可以看成是有Series组成的字典,DataFrame中的数据可以是一个或者多个二维块组成(不是列表、字典或其他一维数据结构)。
data = {'city': ['BeiJing','WuHan','HangZhou','ShangHai','ChnengDu','ChongQing'],
'gender':[0,1,1,0,1,0],
'age':[24,65,34,80,12,28]})
d1 = pd.DataFrame(data)




自动添加了索引,可以根据指定列的顺序停止陈列。
#相似于Series,假如传入的列没有值,则为空(NaN)
d2 = pd.DataFrame(data,columns=['gender','age','city'])
d3 = pd.DataFrame(data,columns=['gender','age','city','name'],index=[list('abcdef')]







2、性质
#取一列
d1['age'] #为Series对象,前往索引为原DataFrame的索引,等价于d1.age
#0 24
1 65
2 34
3 80
4 12
5 28
Name: age, dtype: int64
#取一行
d1.ix[3]
#age 80
city ShangHai
gender 0
Name: 3, dtype: object
d1.loc[3] #取行做运用.loc或者.iloc。
#age 80
city ShangHai
gender 0
Name: 3, dtype: object
#赋值修正
d3.name = '李四'
#新加入一类
d1['is_men'] = d1.geder==1
s1.values #array格式数据







留意:




构造DataFrame的数据输入格式多种多样,次要有以下几种;




索引对象

pandas索引对象是担任管理轴或者其他元数据,在构建Series或者DataFrame时,所用数组或者其他序列标签都会转换成index。
s3.index
#Index([u'a', u'b', u'c', u'd'], dtype='object')
s3.index[2:]
#Index([u'c', u'd'], dtype='object')
#Index对象不能被修正

index的对象类型:




索引的一些属性和方法:
#可以当成两个一维数组或者Series处理
s1.index.append(s3.index)
#Index([0, 1, 2, 3, 4, 5, u'a', u'b', u'c', u'd'], dtype='object')
时s3.index.is_unique #True
s3.index.nunqiue() #4



基本功能

本章将重点讲解在数据分析中Series和DataFrame常用途理方法。
重新索引
reindex方法,重新索引,即创建一个新索引的新对象。适用于Series和DataFrame
1、Series
####对于Series
s1 = pd.Series({'a':1,'b':2,'c':3,'d':4})
#根据新索引重新陈列,索引值不存在即为缺失值,fill_value表示缺失值的填充
s2 = s1.reindex(list('abcdef'),fill_value=0)
#a 1.0
b 2.0
c 3.0
d 4.0
e 0.0
f 0.0
dtype: float64
#对于工夫序列,重新索引可以经过method参数引入插值
s3 = pd.Series(['a','b','c'],index=[0,2,4])
#ffill表示前向填充,bfill表示后向
s4 = s3.reindex(range(6),method='ffill')
#0 a
1 a
2 b
3 b
4 c
5 c
dtype: object

2、DataFrame

对于DataFrame,reindex既可以修正行索引,也可以修正列索引。
index = ['Firefox', 'Chrome', 'Safari', 'IE10', 'Konqueror']
df = pd.DataFrame({
'http_status': [200,200,404,404,301],
'response_time': [0.04, 0.02, 0.07, 0.08, 1.0]},
index=index)
df
# http_status response_time
Firefox 200 0.04
Chrome 200 0.02
Safari 404 0.07
IE10 404 0.08
Konqueror 301 1.0
#重新行索引
new_index= ['Safari', 'Iceweasel', 'Comodo Dragon', 'IE10','Chrome']
df.reindex(new_index)
df
# http_status response_time
Safari 404.0 0.07
Iceweasel NaN NaN
Comodo Dragon NaN NaN
IE10 404.0 0.08
Chrome 200.0 0.02
#缺失值填充
df.reindex(new_index, fill_value=0)
# http_status response_time
Safari 404 0.07
Iceweasel 0 0.00
Comodo Dragon 0 0.00
IE10 404 0.08
Chrome 200 0.02
#重新列索引
df.reindex(columns=['http_status', 'user_agent'])
#等价于df.reindex(['http_status', 'user_agent'], axis="columns")
# http_status user_agent
Firefox 200 NaN
Chrome 200 NaN
Safari 404 NaN
IE10 404 NaN
Konqueror 301 NaN
#对于数据序列的重新索引成绩
date_index = pd.date_range('1/1/2010', periods=6, freq='D')
df2 = pd.DataFrame({"prices": [100, 101, np.nan, 100, 89, 88]},
index=date_index)
df2
# prices
2010-01-01 100.0
2010-01-02 101.0
2010-01-03 NaN
2010-01-04 100.0
2010-01-05 89.0
2010-01-06 88.0
date_index2 = pd.date_range('12/29/2009', periods=10, freq='D')
df2.reindex(date_index2)
# prices
2009-12-29 NaN
2009-12-30 NaN
2009-12-31 NaN
2010-01-01 100.0
2010-01-02 101.0
2010-01-03 NaN
2010-01-04 100.0
2010-01-05 89.0
2010-01-06 88.0
2010-01-07 NaN
df2.reindex(date_index2, method='bfill')
# prices
2009-12-29 100.0
2009-12-30 100.0
2009-12-31 100.0
2010-01-01 100.0
2010-01-02 101.0
2010-01-03 NaN
2010-01-04 100.0
2010-01-05 89.0
2010-01-06 88.0
2010-01-07 NaN

3、参数阐明




行列挑选
#series
s1 =pd.Series(np.arange(5.), index=['a', 'b', 'c', 'd', 'e'])
new_obj = s1.drop(['b','c']) #行删除
new_obj
a 0.0
b 1.0
e 4.0
dtype: float64
#DataFrame
df1 = pd.DataFrame(np.arange(16).reshape((4, 4)),
index=['Ohio', 'Colorado', 'Utah', 'New York'],
columns=['one', 'two', 'three', 'four'])
df1.drop(['Colorado', 'Ohio']) #行删除
df1.drop('two', axis=1) #列删除,axis默以为0轴

索引、选取、过滤

1、运用
s1 = pd.Series(np.arange(4), index=['a', 'b', 'c', 'd'])
s1['b'] #1.0
s1[1] #1.0
s1[2:4]
#c 2.0
d 3.0
dtype: float64
s1[['b', 'a', 'd']]
#b 1.0
a 0.0
d 3.0
dtype: float64
s1[obj < 2]
#a 0.0
b 1.0
dtype: float64
obj['b':'c'] = 5
obj
#a 0.0
b 5.0
c 5.0
d 3.0
#DataFrame
df1 = pd.DataFrame(np.arange(16).reshape((4, 4)),
index=['Ohio', 'Colorado', 'Utah', 'New York'],
columns=['one', 'two', 'three', 'four'])
df1
# one two three four
Ohio 0 1 2 3
Colorado 4 5 6 7
Utah 8 9 10 11
New York 12 13 14 15
df1['two'] #选列
#Ohio 1
Colorado 5
Utah 9
New York 13
Name: two, dtype: int64
df1[['three', 'one']] #选多列
# three one
Ohio 2 0
Colorado 6 4
Utah 10 8
New York 14 12
df1[:2] #选多行
# one two three four
Ohio 0 1 2 3
Colorado 4 5 6 7
df1[df1['three'] > 5]#挑选
# one two three four
Colorado 4 5 6 7
Utah 8 9 10 11
New York 12 13 14 15
df1 < 5
# one two three four
Ohio True True True True
Colorado True False False False
Utah False False False False
New York False False False False
df1[data < 5] = 0 #赋值
# one two three four
Ohio 0 1 2 3
Colorado 4 5 6 7
Utah 8 9 10 11
New York 12 13 14 15
df1.ix['Colorado', ['two', 'three']] #行列挑选
#two 5
three 6
Name: Colorado, dtype: int64
df1.ix[['Colorado', 'Utah'], [3, 0, 1]]
# four one two
Colorado 7 4 5
Utah 11 8 9
df1.ix[2]
#one 8
two 9
three 10
four 11
Name: Utah, dtype: int64
#df1.ix[data.three > 5, :3]
# one two three
Colorado 4 5 6
Utah 8 9 10
New York 12 13 14
#注:在最近的版本中,挑选数据运用.ix易出现正告,建议运用.loc,.iloc

2、索引选项







运算与数据对齐

pandas可以对不同索引的对象停止算术运算,运算后对象的索引相当于索引对的并集。

1、算术运算
s1 = pd.Series([7.3, -2.5, 3.4, 1.5], index=['a', 'c', 'd', 'e'])
s2 = pd.Series([-2.1, -1.5, 4, 3.1], index=['a', 'e', 'f', 'g'])
s1+s2
#a 5.2
c NaN
d NaN
e 0.0
f NaN
g NaN
dtype: float64
df1 = pd.DataFrame(np.arange(9).reshape((3, 3)), columns=list('bcd'),
index=['Ohio', 'Texas', 'Colorado'])
df2 = pd.DataFrame(np.arange(12).reshape((4, 3)), columns=list('bde'),
index=['Utah', 'Ohio', 'Texas', 'Oregon'])
df1+df2
# a b c d e
0 0.0 2.0 4.0 6.0 NaN
1 9.0 11.0 13.0 15.0 NaN
2 18.0 20.0 22.0 24.0 NaN
3 NaN NaN NaN NaN NaN
#缺失填充
df1.add(df2, fill_value=0)
# a b c d e
0 0.0 2.0 4.0 6.0 4.0
1 9.0 11.0 13.0 15.0 9.0
2 18.0 20.0 22.0 24.0 14.0
3 15.0 16.0 17.0 18.0 19.0
#Series与DataFrame之间的运算,与不同外形数组之间的运算相似
df1= pd.DataFrame(np.arange(12.).reshape((4, 3)), columns=list('bde'),
index=['Utah', 'Ohio', 'Texas', 'Oregon'])
s1= df1.ix[0]
df1-s1
# b d e
Utah 0.0 0.0 0.0
Ohio 3.0 3.0 3.0
Texas 6.0 6.0 6.0
Oregon 9.0 9.0 9.0
s2 = df1['d']
df1.sub(s2, axis=0) #减法,广播
# b d e
Utah -1.0 0.0 1.0
Ohio -1.0 0.0 1.0
Texas -1.0 0.0 1.0
Oregon -1.0 0.0 1.0

函数运用和映射

次要引见在pandas运用中常用的apply()、map()、applymap()三种方法。
    apply()applymap()map()
#df2= pd.DataFrame(np.random.randn(4, 3), columns=list('bde'),
index=['Utah', 'Ohio', 'Texas', 'Oregon'])
np.abs(df2)
# b d e
Utah 0.690002 1.001543 0.503087
Ohio 0.622274 0.921169 0.726213
Texas 0.222896 0.051316 1.157719
Oregon 0.816707 0.433610 1.010737
#apply方法,运用中既可以是Python内置函数,也可以是本人构造
f = lambda x: x.max() - x.min()
df2.apply(f) #默许0轴
#b 1.802165
d 1.684034
e 2.689627
dtype: float64
df2.apply(f, axis=1)
#Utah 0.998382
Ohio 2.521511
Texas 0.676115
Oregon 2.542656
dtype: float
#applymap方法
f1 = lambda x: '%.2f' % x
df2.applymap(f1)
# b d e
Utah 0.69 1.00 -0.50
Ohio -0.62 -0.92 -0.73
Texas 0.22 0.05 -1.16
Oregon 0.82 0.43 1.01
#map方法
df2['e'].map(format)
#Utah -0.50
Ohio -0.73
Texas -1.16
Oregon 1.01
Name: e, dtype: objec

排序和排名

对DataFrame(Series)中的行或者列停止排序或者排名是数据分析中非常重要的内置运算。
    sort_index():次要用来停止行(列)索引排序。sort_values():次要对某一列(行)停止排序。rank():

1、sort_index

sort_index(axis=0, level=None, ascending=True, inplace=False, kind='quicksort', na_position='last', sort_remaining=True, by=None)




运用实例:
s1 = pd.Series(range(4), index=['d', 'a', 'b', 'c'])
s1.sort_index()
#a 1
b 2
c 3
d 0
dtype: int64
#按行索引排序
df1 = DataFrame(np.arange(8).reshape((2, 4)), index=['three', 'one'],
columns=['d', 'a', 'b', 'c'])
df1.sort_index()
# d a b c
one 4 5 6 7
three 0 1 2 3
#按列索引排序
df1.sort_index(axis=1)
# a b c d
three 1 2 3 0
one 5 6 7 4
#列索引递减
df1.sort_index(axis=1, ascending=False)
# d c b a
three 0 3 2 1
one 4 7 6 5

2、sort_values

sort_values(by=None,axis=0,ascending=True, inplace=False, na_position=‘last’)




运用实例:
df1 = pd.DataFrame({'c1':['A','B','B',np.nan,'C','D'],
'c2':[1,1,4,2,3,7],
'c3':[0,1,5,3,1,6]})
#按列
df1.sort_values(by=['c1'],ascending=False,na_position='first')
# c1 c2 c3
3 NaN 2 3
5 D 7 6
4 C 3 1
1 B 1 1
2 B 4 5
0 A 1 0
df1.sort_values(by=['c2','c3'],ascending=False)
# c1 c2 c3
5 D 7 6
2 B 4 5
4 C 3 1
3 NaN 2 3
1 B 1 1
0 A 1 0
#按行
df1.sort_values(by=2,ascending=False,axis=1)
# c1 c3 c2
3 NaN 3 2
5 D 6 7
4 C 1 3
1 B 1 1
2 B 5 4
0 A 0 1
df1.sort_values(by=['c1'],na_position='first')
# c1 c2 c3
3 NaN 2 3
0 A 1 0
1 B 1 1
2 B 4 5
4 C 3 1
5 D 7 6

3、rank

rank(axis=0, method='average', numeric_only=None, na_option='keep', ascending=True, pct=False)

次要参数阐明:




运用实例:
s1= pd.Series([5, 9, 2, 10, 9, 2, 0])
s1.rank() #遇到两个数相等,就取这两个数排名的平均值
0 4.0
1 5.5
2 2.5
3 7.0
4 5.5
5 2.5
6 1.0
dtype: float64
s1.rank(method='first')
#0 4.0
1 5.0
2 2.0
3 7.0
4 6.0
5 3.0
6 1.0
dtype: float64
s1.rank(method='max')
#0 4.0
1 6.0
2 3.0
3 7.0
4 6.0
5 3.0
6 1.0
dtype: float64
df1 = pd.DataFrame({'b': [4.3, 7, -3, 2], 'a': [0, 1, 0, 1],
'c': [-2, 5, 8, -2.5]})
df1.rank(axis=1)
# a b c
0 2.0 3.0 1.0
1 1.0 3.0 2.0
2 2.0 1.0 3.0
3 2.0 3.0 1.0
df1.rank()
# a b c
0 1.5 3.0 2.0
1 3.5 4.0 3.0
2 1.5 1.0 4.0
3 3.5 2.0 1.0

统计与计算

引见一些pandas常用的数学以及统计方法。
df1 = pd.DataFrame([[1.4, np.nan], [7.1, -4.5],
[np.nan, np.nan], [0.75, -1.3]],
index=['a', 'b', 'c', 'd'],
columns=['one', 'two'])
df1.sum() #axis表示按照哪个轴停止计算
#one 9.25
two -5.80
dtype: float64
df1.mean(axis=1, skipna=False)
#a NaN
b 1.300
c NaN
d -0.275
dtype: float64
df.idxmax() #最大值对应的索引
#one b
two d
dtype: object
df1.cumsum() #累加
# one two
a 1.40 NaN
b 8.50 -4.5
c NaN NaN
d 9.25 -5.8
df1.describe()
# one two
count 3.000000 2.000000
mean 3.083333 -2.900000
std 3.493685 2.262742
min 0.750000 -4.500000
25% 1.075000 -3.700000
50% 1.400000 -2.900000
75% 4.250000 -2.100000
max 7.100000 -1.300000

缺失值处理

缺失值的处理是数据分析中一个重要的知识点,pandas在处理缺失值方面也提供一些重要的方法。
    isnull()notnull()dropna()fillna()
s1= pd.Series(['aardvark', 'artichoke', np.nan, 'avocado'])
s1.isnull() #判别系列外面元素缺失,是前往True
#0 False
1 False
2 True
3 False
dtype: bool
s1.notnull() #判别系列外面元素不缺失,是前往True
#0 True
1 True
2 False
3 True
dtype: bool
#pandas内置的None也被以为是缺失值
#经过缺失值停止数据挑选
s1[s1.notnull()]
#0 aardvark
1 artichoke
3 avocado
dtype: object
#缺失值过滤
s1.dropna() #对于DataFrame有一些参数
0 aardvark
1 artichoke
3 avocado
dtype: object
from numpy import nan as NA
data = DataFrame([[1., 6.5, 3.], [1., NA, NA],
[NA, NA, NA], [NA, 6.5, 3.]])
data.dropna() #默许删除有缺失值的行
#        0        1        2
0        1.0        6.5        3.0
data.dropna(how='all') #删除全部缺失的行
# 0 1 2
0 1.0 6.5 3.0
1 1.0 NaN NaN
3 NaN 6.5 3.0
data[4] = NA #加一列全部缺失
data.dropna(axis=1, how='all') #按列删除全缺失的
# 0 1 2
0 1.0 6.5 3.0
1 1.0 NaN NaN
2 NaN NaN NaN
3 NaN 6.5 3.0
data.dropna(thresh=3) #按行非缺失值的个数
# 0 1 2 4
0 1.0 6.5 3.0 NaN
data.dropna(subset=[0,1,2],thresh=1) #subset设置需求统计的列范围
# 0 1 2 4
0 1.0 6.5 3.0 NaN
1 1.0 NaN NaN NaN
3 NaN 6.5 3.0 NaN
#缺失填充
df1 = DataFrame(np.random.randn(7, 3))
df1.ix[:4, 1] = NA; df1.ix[:2, 2] = NA
df1
# 0 1 2
0 1.824875 NaN NaN
1 -0.131578 NaN NaN
2 2.169461 NaN NaN
3 0.029610 NaN 0.118110
4 -0.748532 NaN 0.152677
5 -1.565657 -0.562540 -0.032664
6 -0.929006 -0.482573 -0.036264
df1.fillna(0)
# 0 1 2
0 1.824875 0.000000 0.000000
1 -0.131578 0.000000 0.000000
2 2.169461 0.000000 0.000000
3 0.029610 0.000000 0.118110
4 -0.748532 0.000000 0.152677
5 -1.565657 -0.562540 -0.032664
6 -0.929006 -0.482573 -0.036264
df1.fillna({1: 0.5, 3: -1}) #按列填充
# 0 1 2
0 1.824875 0.500000 NaN
1 -0.131578 0.500000 NaN
2 2.169461 0.500000 NaN
3 0.029610 0.500000 0.118110
4 -0.748532 0.500000 0.152677
5 -1.565657 -0.562540 -0.032664
6 -0.929006 -0.482573 -0.03626

层次化索引

层次化索引是pandas中一个重要的功能,它可以让数据在一个轴上有两个或以上的索引,这样可以以低维方式处理高维数据。
df1= Series(np.random.randn(10),
index=[['a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'd', 'd'],
[1, 2, 3, 1, 2, 3, 1, 2, 2, 3]])
df1
#a 1 0.670216
2 0.852965
3 -0.955869
b 1 -0.023493
2 -2.304234
3 -0.652469
c 1 -1.218302
2 -1.332610
d 2 1.074623
3 0.723642
dtype: float64
df1.index #索引
#MultiIndex(levels=[[u'a', u'b', u'c', u'd'], [1, 2, 3]],
codes=[[0, 0, 0, 1, 1, 1, 2, 2, 3, 3], [0, 1, 2, 0, 1, 2, 0, 1, 1, 2]])
df['b'] #取数据
#1 -0.023493
2 -2.304234
3 -0.652469
dtype: float64
df['b':'c']
#b 1 -0.023493
2 -2.304234
3 -0.652469
c 1 -1.218302
2 -1.332610
dtype: float64
df1.ix[['b', 'd']]
#b 1 -0.023493
2 -2.304234
3 -0.652469
d 2 1.074623
3 0.723642
dtype: float64
df1.unstack() #数据重塑
# 1 2 3
a 1.095390 0.980928 -0.589488
b 1.581700 -0.528735 0.457002
c 0.929969 -1.569271 NaN
d NaN -1.022487 -0.402827
数据读存与文件格式

数据读取与存储

pandas提供了一系列将表格型数据读取为DataFrame对象的函数,如下图所示:




以read_csv读取数据为例:

read_csv(filepath_or_buffer, sep=', ', delimiter=None, header='infer', names=None, index_col=None, usecols=None, squeeze=False, prefix=None, mangle_dupe_cols=True, dtype=None, engine=None, converters=None, true_values=None, false_values=None, skipinitialspace=False, skiprows=None, skipfooter=0, nrows=None, na_values=None, keep_default_na=True, na_filter=True, verbose=False, skip_blank_lines=True, parse_dates=False, infer_datetime_format=False, keep_date_col=False, date_parser=None, dayfirst=False, iterator=False, chunksize=None, compression='infer', thousands=None, decimal=b'.', lineterminator=None, quotechar='"', quoting=0, doublequote=True, escapechar=None, comment=None, encoding=None, dialect=None, tupleize_cols=None, error_bad_lines=True, warn_bad_lines=True, delim_whitespace=False, low_memory=True, memory_map=False, float_precision=None)

参数含义:










关于存储数据pandas提供了to_csv()方法,用法相似于read_csv(),在这里不再展开。

手工处理分隔符数据

由于有一些文件含义有些有成绩的数据行,直接运用pandas自带的数据读取方法能够会出现成绩,因此需求一些手工处理。本节引见python内置的csv模块处理数据。
import csv
#csv读取数据
f = open('file.csv')
reader = csv.reader(f)
for line in reader:
print(line) #每一行以列表的方式呈现
#数据解析
lines = list(csv.reader(open('file.csv')))
header, values = lines[0], lines[1:]
data_dict = {h: v for h, v in zip(header, zip(*values))}

csv参数解释:




JSON数据

JSON是一种比表格型文本格式更灵敏的数据格式。
json_data= """
{"name": "Wes",
"places_lived": ["United States", "Spain", "Germany"],
"pet": null,
"siblings": [{"name": "Scott", "age": 25, "pet": "Zuko"},
{"name": "Katie", "age": 33, "pet": "Cisco"}]
}
"""
import json
#json数据读取
result = json.loads(json_data)
#数据存储为json格式
as_json = json.dumps(result)

总结

这是pandas数据分析引见的上半部分,次要是引见pandas中最重要的楼主和数据结构以及比较常规的运用方法,一些文件读存方法。在pandas下半部分里将重点引见pandas数据分析中的清洗、转换、合并、重塑以及数据聚合和分组运算方面的内容。

写在最后

在当下的AI学习中,缺的不是学习材料,缺的是一颗持之以恒的心,不要怕本人零基础,不要怕本人不是半路出家,也不要怕曾经30+,更不要怕本人不是211、985,在当下的互联网面试中,完全的不看这些是不能够,但是才能,特别是技术实力是决议能否能拿到offer的关键,记住,兴味是第一位;努力是第二位,只需你满足这些,踏实学习下去,即便走得比别人慢,你也一定会有播种。

本来想本人制造与机器学习相关的视频专栏,可是工作太忙没有工夫,在这里给大家引荐一个Python数据分析的视频专栏,这是我近期看到制造的最好的视频了,大家可以了解一下。关于付费的学习视频,我的建议是合适本人的才是最好了,不要觉得便宜买;也不要觉得贵不买,投资本人永远不会是赔本的。最后,无论你是在校先生、互联网转行者、码农.....,只需在职业规划或者机器学习方面任何迷茫或者不懂的成绩都可以加我的微信(Loving_AI)或者后台私信我。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

大神点评4

那夜我错了 2019-6-11 13:03:30 显示全部楼层
分享了
回复

使用道具 举报

中意你cy 2019-6-11 13:13:09 显示全部楼层
谢谢分享
回复

使用道具 举报

筱筱ye 2019-6-12 14:37:07 显示全部楼层
楼猪V5啊
回复

使用道具 举报

同桌的她 2019-6-13 15:47:11 显示全部楼层
这么强,支持楼主,佩服
回复

使用道具 举报

高级模式
B Color Image Link Quote Code Smilies