1. 程式人生 > >對資料的處理函式

對資料的處理函式

zip函式把東西打包成一個以逗號為分隔的元組

weather_dict = dict(zip(regions, zip(weather_stations, region_names, cities)))
weather_dict
{'CAPITL': ('kalb', 'Capital', 'Albany'),'WEST': ('kpbg', 'North', 'Plattsburgh')}

Python 語言來編碼和解碼 JSON 物件,參考菜鳥教程例子以及農作物比賽的原始碼

從excel中匯入資料到程式中:

df = pd.read_excel(r'C:\Users\27058\Desktop\program\1.xlsx
')

//df為pd物件,可直接以df[列名]來訪問每條資料

df = df[['timestamp', 'name', 'ptid', 'load']]

//選取所得資料中的某幾列

df.to_csv('../data/nyiso/all/combined_iso.csv', index=False)

//選的資料重新寫入檔案

 

format函式對字串進行格式化處理,參考例項:http://www.runoob.com/python/att-string-format.html

 

 

 

對兩個列表進行遍歷,分別操作兩個列表元素

1 >>> list1 = ['
a', 'b', 'c', 'd'] 2 >>> list2 = ['apple', 'boy', 'cat', 'dog'] 3 >>> for x, y in zip(list1, list2): 4   print(x, 'is', y) 5 # 輸出 6 a is apple 7 b is boy 8 c is cat 9 d is dog

 numpy.around(array,n) 函式對np陣列元素取小數點後n位

例:

shu1_y_pre=np.around(shu1_y_pre,1)