numpy dataframe筆記

Steven Wang
Mar 4, 2022

--

學好plot為dash的基礎

import numpy as np
mylist=[1,2,3,4]
np.array(mylist)
np.arange(0,10)
np.arange(0,10,2)
np.zeros((5,5))
np.zeros((1,10))
np.zeros((2,10))
np.ones((2,4))
np.random.randint(0,100)
np.random.randint(0,100,(5,5))
np.linspace(0,10,6)
np.linspace(0,10,101)
np.linspace(0,10,200) 範圍內等距取N個值

np.random.seed(N). 才會取出一樣的值
np.random.randint(0,100,10)

arr=np.random.randint(0,100,10)
arr.max()
arr.min()
arr.min
arr.mean()
arr.argmax()最大值index的位置
arr.argmin()

arr.reshape(2,5)

mat = np.arange(0,100).reshape(10,10)
mat[5,2]
mat[:,2]
mat[2,:]
mat>50 > true/false
mat[mat>50] >取出>50的值

pandas allow python to read in dataset from various formats , such as CSV

df = pd.read_csv(‘filename.csv’)
print(df)
print(df[‘salary’])
print(df[[‘name’,’salary’]])
print(df[‘salary’].mean())

ser_of_bool=df[‘age’]>30 傳回T/F
print(df[ser_of_bool])
print(df[df[‘age’]>30])
print(df[‘age].unique())

print(df.columns) >df欄位名稱
print(df.info())
print(df.describe())
print(df.index)

mat=np.arange(0,50).reshape(5,10)
df=pd.DataFrame(data=mat)
df=pd.DataFrame(data=mat,columns=[‘A’,’B’]
df=pd.DataFrame(data=mat,columns=[‘A’,’B’],index=[])

--

--

Steven Wang
Steven Wang

No responses yet