import numpy as np
import pandas as pd
NumPy 一维数组
a = np. array( [ 2 , 3 , 4 , 5 ] )
a[ 0 ] >= 2
True
a[ 1 : 4 ]
array([3, 4, 5])
for i in a :
print ( i)
2
3
4
5
a. dtype
dtype('int32')
a. mean( )
3.5
a. std( )
1.1180339887498949
b= np. array( [ 1 , 2 , 3 ] )
c= b+ 1
c
array([2, 3, 4])
c= b* 4
c
array([ 4, 8, 12])
一维数据分析:Pandas
stock6 = pd. Series( [ 54.74 , 190.9 , 173.14 , 1050.3 , 181.86 , 1139.49 ] ,
index = [ '腾讯' ,
'阿里巴巴' ,
'苹果' ,
'谷歌' ,
'Facebook' ,
'亚马逊' ] )
stock6
腾讯 54.74
阿里巴巴 190.90
苹果 173.14
谷歌 1050.30
Facebook 181.86
亚马逊 1139.49
dtype: float64
stock6. describe( )
count 6.000000
mean 465.071667
std 491.183757
min 54.740000
25% 175.320000
50% 186.380000
75% 835.450000
max 1139.490000
dtype: float64
stock6. iloc[ 0 ]
54.740000000000002
stock6. loc[ '腾讯' ]
54.740000000000002
s1 = pd. Series( [ 1 , 2 , 3 , 4 ] , index = [ 'a' , 'b' , 'c' , 'd' ] )
s2 = pd. Series( [ 10 , 20 , 30 , 40 ] , index = [ 'a' , 'b' , 'e' , 'f' ] )
s3 = s1 + s2
s3
a 11.0
b 22.0
c NaN
d NaN
e NaN
f NaN
dtype: float64
s3. dropna( )
a 11.0
b 22.0
dtype: float64
s3 = s1. add( s2, fill_value = 0 )
s3
a 11.0
b 22.0
c 3.0
d 4.0
e 30.0
f 40.0
dtype: float64