python數據處理常用函數
阿新 • • 發佈:2019-02-28
dex 數據 das head col data port file 常用函數
1 . pandas
import pandas as pd ## 讀取 data = pd.read_csv(filename,header=None) data =data.values print(data.shape) ##此時 data 可作為numpy 數組來使用 ## 保存 ## 將 list 轉化為 numpy 格式 data_numpy = np.array(data_list) ## 將numpy 數組 轉化為 pandas 格式來保存 data_numpy = pd.DataFrame(data_numpy, index=None, columns=None) data_numpy.to_csv(filename', header=None, index=None)
2. PIL Pillow
## 讀取圖片 在圖片上繪圖
from PIL import Image, ImageDraw
im = Image.open('1.jpg')
im.show()
im.save('2.jpg')
draw = ImageDraw.Draw(im)
draw.line([(x1,y1),(x2,y2)], fill = (255,0,0), width = 5)
im.show()
im.save('3.jpg')
python數據處理常用函數