【Python - 100天从新手到大师】——pandas入门

原文链接:https://github.com/jackfrued/Python-100-Days

【Python - 100天从新手到大师】

import numpy as np
import pandas as pd
from pandas import Series,DataFrame
# 创建
# Series是一维的数据
s = Series(data = [120,136,128,99],index = ['Math','Python','En','Chinese'])
s

》》》 Math       120
	  Python     136
	  En         128
	  Chinese     99
	  dtype: int64
s.shape

》》》 (4,)
v = s.values
v

》》》 array([120, 136, 128,  99], dtype=int64)
type(v)

》》》 numpy.ndarray
s.mean()

》》》 120.75
s.max()

》》》 136
s.std()

》》》 15.903353943953666
s.pow(2)

》》》 Math       14400
	  Python     18496
	  En         16384
	  Chinese     9801
	  dtype: int64
# DataFrame是二维的数据
# excel就非诚相似
# 所有进行数据分析,数据挖掘的工具最基础的结果:行和列,行表示样本,列表示的是属性
df = DataFrame(data = np.random.randint(0,150,size = (10,3)),index = list('abcdefhijk'),columns=['Python','En','Math'])
df

在这里插入图片描述

df.shape

》》》 (10, 3)
v = df.values
v

》》》 array([[113, 116,  75],
       		 [ 19, 145,  23],
       		 [ 57, 107, 113],
       		 [ 95,   3,  66],
       		 [ 28, 121, 120],
       		 [141,  85, 132],
       		 [124,  39,  10],
       		 [ 80,  35,  17],
       		 [ 68,  99,  31],
       		 [ 74,  12,  11]])
df.mean()

》》》 Python    79.9
	  En        76.2
	  Math      59.8
	  dtype: float64
df.max()

》》》 Python    141
	  En        145
	  Math      132
	  dtype: int32
df

在这里插入图片描述

df.mean(axis = 0)

》》》 Python    79.9
	  En        76.2
	  Math      59.8
	  dtype: float64
df.mean(axis = 1)

》》》 a    101.333333
	  b     62.333333
	  c     92.333333
	  d     54.666667
	  e     89.666667
	  f    119.333333
	  h     57.666667
	  i     44.000000
	  j     66.000000
	  k     32.333333
	  dtype: float64

猜你喜欢

转载自blog.csdn.net/TeFuirnever/article/details/94564533