一、數(shù)據(jù)類型
1.變量名
首字母不能是數(shù)字和_
大小寫敏感
不能用保留字
2.數(shù)據(jù)類型
數(shù)值型:1,2,3
字符串:“1”跳纳,“2”疟暖,“3”
布爾型:True, False ? 與或非:&蜜葱,| ,not
3.運(yùn)算規(guī)則
3.1數(shù)值型
取整:7//4 = 1
求余:10%4=2
冪:2**3 = 8
浮點(diǎn)數(shù)越界:a=4.2, b=2.1,(a+b) == 6.3返回False
需要from decimal import Decimal
a = Decimal('4.2')才可以
3.2字符型
\轉(zhuǎn)義字符全景, \n換行, \t tab等等
原始字符串:r‘C:\your\path’牵囤, 避免使用一大推轉(zhuǎn)義
3.3邏輯型
與或非
二爸黄、數(shù)據(jù)結(jié)構(gòu)
1.列Series
定義
from pandas import Series
x = Series(['a',True, 1])
可以自定義索引滞伟,x = Series(['a',True, 1], index = ['one','two', 'three'])
增刪改查
索引從0開(kāi)始,x[1] = True
添加append
刪除drop
切片x[1:3]
2. 表DataFrame
from pandas import DataFrame
df = DataFrame('age'=[21,22,23], 'name'=['a', 'b', 'c'])
訪問(wèn)行 df = [1:2]
行索引 df.loc[['one','two']]
行列號(hào) df.iloc[0:1, 0:1]
行索引+列名 df.at['first', 'name']
修改列名 df.columns = ['name1','name2']
修改行索引 df.index = range(1,4)
刪除 df.drop() axis = 0刪除行 axis=1刪除列