Python+numpy pandas 3편

Click here to load reader

  • date post

    08-Jan-2017
  • Category

    Software

  • view

    133
  • download

    8

Embed Size (px)

Transcript of Python+numpy pandas 3편

PowerPoint

Moon Yong Joon1Python numpy,pandas-3

6. Pandas 7. Pandas Series/ DataFrame 8.Pandas series/dataframe 9. Pandas index class10.Pandas groupby 11. Pandas panel(3)2

36. Pandas

4Pandas

Pandas

5

1 dict index value 6Series : 1

index

012 data:

index : index.name index name

dtypes :

name : Series values

dtypes

1 index 7Series

Series DataFrame columns series index series index 8DataFrame : 2

Index()Column()

col1col2col3row1row2row3

index

012values

dtype

name

index

012values

dtype

name

index

012values

dtype

name

Series DataFrame

n*m index column , column 9DataFrame

Index()Column()

col1col2col3row1row2row3

3 10Panel : 3

index

item0item1data

Index()Column()

col1col2col3row1row2row3DataFrame

Index()Column()

col1col2col3row1row2row3

data = {'Item1' : pd.DataFrame(np.random.randn(3, 3)), 'Item2' : pd.DataFrame(np.random.randn(3, 3))}pd.Panel(data)

Index/slice

11

[ ] 12 [0,0][0,1][0,2]Row : Column: 0012[0,0][0,1][0,2]Column: 0abc

[ ] (scalar) (Series) 13, [0,0]Row : Column: [0,0][0,1][0,2]Row : Column: 0012

[ ] 2 3 14 2/3 [0,0][0,1][0,2][1,0][1,1][1,2][2,0][2,1][2,2]Row : Column: 012012

Index

15

labels, names 16Index

Index()Column()

col1col2col3row1row2row3labelsnamesIndex Levels labelsnamesColumn Levels Index()Column()

Levels, labels, names 17multiIndex

Index()Column()

col1col2col3row1row2row3levelslabelsnamesIndex Index Levels levelslabelsnamesColumn Column Levels Index()Column()row1row2row3col1col2col3

18Pandas Series class

Series

19

1 20Series pandas.Series(data,index,dtypes,name,copy)

class

21

List Series 22Series : list-like

dict index, values Series 23Series : dict-like

Series value ndarray index Index 24Series data type

Index

25

Index name index name 26Series :index name

Series index/slice

27

Index RangeIndex, index Int64Index, Index 28Series : index

Index

RangeIndex, Index index 29Series : slice

slice

Fancy

30

True/False True 31Series :

Fancy [ ] index 32Series :fancy

33Pandas DataFrame class

DataFrame class

34

n*m 35DataFrame class DataFrame(pandas.core.generic.NDFrame)

| 2 | Parameters | ---------- | data : numpy.ndarray ,dict, or DataFrame | dict can contain Series, arrays, constants, or list-like objects | index : Index or array-like | np.arange(n), | columns : Index or array-like np.arange(n), | dtype : dtype, default None | Data type to force, otherwise infer | copy : boolean, default False | Copy data from inputs. Only affects DataFrame / 2d ndarray input

Series DataFrame Series DataFrame values ndarray 2 36DataFrame data type

DataFrame value ndarray index Index 37DataFrame data type

class

38

DataFrame column 39DataFrame : 1 column

col1row1row2row3

column zip 40DataFrame : list/tuple

column dict key columns 41DataFrame : dict

DataFrame columns 42DataFrame :

Series

43

series dataframe series index (index) series name (column) 44Dataframe : Series 1

series list dataframe series index series name index 45Dataframe : list(Series)

List

series dict dataframe series index index series name columns 46Dataframe : dict(Series) 1

series dict dataframe series index index series name columns 47Dataframe : dict(Series) 2

series dict comprehension dataframe series index index series name columns 48Dataframe : dict comprehension

Index/columns

49

Index 50DataFrame index

DataFrame (index )51DataFrame : index

col1row1row2row3

col2

DataFrame column 52DataFrame : column

col1row1row2row3

DataFrame

53

DataFrame. 54DataFrame

DataFrame (index )55DataFrame

col1row1row2row3

col2

56DataFrame :

DataFrame ([ ])57DataFrame : column

col1row1row2row3

col2

DataFrame ([ [ , ] ]) 58DataFrame : multi column

col1row1row2row3

col2

DataFrame

59

DataFrame True 60DataFrame :

DataFrame Fancy

61

[[ ]] 62DataFrame :

([[]]) 63DataFrame :

64Pandas

65

Pandas class 66 Series class

DataFrame class

Series index KeyError 67Series : No Index

Series index KeyError get() index 68Series : get()

DataFrame index KeyError 69DataFrame : No Index

DataFrame index KeyError get() index 70DataFrame : get()

71

Serise DataFrame view copy 72

copy (==) (is) 73Series : copy

copy (==) (is) 74DataFrame : copy

groupby

75

group 76Groupby letteronetwo0a121a122b123b124c12

onetwolettera24b24c12

letteronetwo0a121a122b123b124c12

twoletteronea14b14c12

Apply

77

Apply 78Dataframe

Index()Column()

col1col2col3row1row2row3 df.apply(func)Apply func(df )

Index()Column()

col1col2col3row1row2row3

79Pandas Matplotlib

Plot

80

Series matplotlib 81Series

DataFrame matplotlib 82DataFrame

837. Pandas Series/Dataframe

Series

84

Index index, values 85Series 1nameSeries shapeDataFrame dtypes ndim strides index index values data Numpy

86Series 2size ftypesReturn the ftypes (indication of sparse/dense and dtype) in this object.axes empty True Falsebase

Axes() Index , index(0) labels 87 attribute : axes

88Series 3T

89Series

Series view

90

blocks, ix, iat,at,iloc,loc 91Series view

Series view : block

92

Series dict 93Series : blocksdtypes

index

012values

Key(dtype)Value(Series)Series

Seriesdict

Series view : ix

94

Series ix label, index 95Series : ix

96Series : ix

Slicing index 97Series : ix slicing

Series view :

98

Series at ,iat 99Series : at/iat

Series loc , 100Series : loc/iloc

101Dataframe

DataFrame

102

dataframe 103DataFrame

Index()Column()

col1col2row1row2row3

Index, columns, shape 104attribute : Index, columns, shape

shapeDataFrame index columns

dtypes, at(indexing/slicing), ndim 105attribute : dtypes, ndim

ndim dtypes

empty, ftypes 106attribute : empty, ftypes

ftypesReturn the ftypes (indication of sparse/dense and dtype) in this object.emptyDataFrame True False

size, values, T 107attribute : size, values, T

size valuesNumpy T

Axes() Index , index(0)/ columns(1) labels 108 attribute : axes

109DataFrame

DataFrame: blocks

110

DataFrame blocks 111 DataFrame.blocks

DataFrame blocks 112 DataFrame.blocks

DataFrame: ix

113

ix 114DataFrame.ix

DataFrame ix series 115 DataFrame.ix

DataFrame ix ([ ( : ), () ])116DataFrame 1

col1row1row2row3

col2

DataFrame ix ([ ( : ), [, ])117DataFrame 2

col1row1row2row3

col2

118row

DataFrame ix series 119 DataFrame.ix

DataFrame: iat/at

120

iat 121DataFrame.iat

at lable 122DataFrame.at

DataFrame: iloc/loc

123

loc 124DataFrame.loc

DataFrame ([ ])125DataFrame

col1row1row2row3

col2

DataFrame ([ : ]) 126DataFrame

col1row1row2row3

col2

iloc (series,) 127DataFrame.iloc

1288. Pandas series/dataframe

129 head/tail

Series

130

Head/tail default 5, n= 131Series head/tail

DataFrame

132

DataFrame head() default=5 133DataFrame head

DataFrame tail() default=5 134DataFrame tail

135

Series

136

Series NaN isnull/notnull 137Isnull/notnull

Series count null 138Series :count

Series value_counts 139Series : value_counts

key index values iteritems index,value 140Iterable : iteritems

series string series.str. 141Series.str

DataFrame

142

count null 143count

Dataframe iterable (column name, Series) 144Iterable : iteritems

Dataframe iterable (index, Series) 145Iterable : iterrows

Dataframe iterable (index, Series) 146Iterable : itertuples

dataframe series string series.str. 147DataFrame: Series.str

148 /

Series

149

1 index 150 get_value/set_value

Series append , index index 151Se