图片灰度化例子
import numpy as np import scipy.misc as sm import matplotlib.pyplot as mp image = sm.imread('1.jpg',True).astype(np.uint8) mp.figure('Image',facecolor='lightgray') mp.title('lily',fontsize=20) mp.axis('off') mp.imshow(image,cmap='gray') mp.show()
import numpy as np import pandas as pd # 创建DataFrame df = pd.DataFrame([['Snow','M',22],['Tyrion','M',32],['Sansa','F',18],['Arya','F',14]], columns=['name','gender','age']) print(df) #选取多列,gender和age列 # print(df.iloc[:,[1,2]]) df.iloc[0,2]=25 df['score']=[80,98,67,90] col_name = df.columns.tolist() # 添加列到某行之后,要先转成list col_name.insert(2,'city') # 添加列到尾 df = df.reindex(columns=col_name) # 重新读入列 df['city']=['1省','2省','3省','4省'] # 赋值给city列 new = pd.DataFrame({'name':'lisa','gender':'f','city':'北京','age':25},index=(4,)) # 要插入的行数据 df =df.append(new,ignore_index =True) # 插入一行之后要赋值 print(df) #df = df.drop(labels='score',axis=1) #删除一列 print(df) df = df.sort_values(by='score',ascending=False) print(df) # # #读取第1行到第2行的数据 # print(df.loc[1:2]) # # #读取第1行和第3行,从第0列到第2列,不包括第二列 # print(df.loc[[1,3],['name','gender']]) # # #读取倒数第3行到倒数第1行的数据 # print(df.iloc[-3:-1,])