numpy

#正态分布
import numpy as np
np.random.normal(0, 1, 100) #μ=0,σ=1

DataFrame增加一列

df['new_column'] = data
df.insert(index, 'flag', array)

DataFrame选择两列

df[['a','b']] 
pd.DataFrame(df,columns = ['s','b'])

python plot

plt.plot(df['a'], df['b'], 'o')
plt.show()

保存文件时索引 https://blog.csdn.net/sinat_29957455/article/details/79059436


fluent python 相关

列表推导和生成器表达式

symbols = '$%x'
codes = [ord(symbol) for symbol in symbols]



#以下效果相同
beyond_ascii = [ord(s) for s in symbols if ord(s)>127]

beyond_ascii = list(filter(lambda c: c>127, map(ord,symbols)))


文件读写

try:
    f = open('file', 'r')
    print(f.read())
finally:
    if f:
        f.close()


with open('file', 'r') as f:
    print(f.read())