JSON 值可以是以下之一:String, Number, Boolean (true, false), Null (null), Object(對應python的dict), Array(對應python的list); Python如何讀取json檔? by 儲蓄保險王 · 2023-07-25 test.txt(json file): code: “[1, 2, 3]”可以轉為list type: 推薦hahow線上學習python: https://igrape.net/30afN 相關文章Python TQC考題: 輸入一個正整數n,並讀取read.txt內容,將首n列的每個英文字首字大寫輸出write.txt ; pandas.Series.str.title() #輸出csv或xlsx時,如何不輸出index 跟 header ? .to_csv( "write.txt", index=False, header=False)Python: pandas, import pandas as pd ; s =pd.Series() ; s.index ; s.values; 類比於dict.keys ; dict.values ; Series有index跟value,可以跟dict互轉;同list的切片可以取值Python import numpy as np ; np.arange(-50, 60, 10); dict(key)提取dict內的元素; importlib.reload(); np.zeros(); np.array()Python: 如何使用functools.reduce逐步縮減可迭代對象,合併為單個結果? import functools; product = functools.reduce( lambda x, y: x * y, numbers) ; reduce(function, sequence [, initial]) -> value ; map(function, iterable) ; filter(function, iterable) ; map ; filterPython: 如何求整個 pandas.DataFrame 中的最大值? pandas.DataFrame .max().max() ; 如何求最大值的index, columns? numpy.where(condition, [x, y, ]/) ; condition為一 bool_maskPython:如何確保只有單欄資料的變數,其型態是 pandas.Series 而非單欄的DataFrame? pandas.DataFrame.squeeze() ; df.set_index() 將兩欄的df,其中一欄設為index後,其型態是單欄的DataFrame還是Series?Python: 字串 str.find(關鍵字[,start][,end]),找不到的話回傳-1,如何找出資料字串中,所有關鍵字的index?詞頻計算Python:如何將x 軸移動到 matplotlib 中繪圖的頂部? ax.xaxis.set_label_position("top") ; ax.xaxis.tick_top() ; ax.set_xticks( ticks=list1, label=list2, rotation=45) #幫刻度值取別名; 如何用loc參數設定title/label位置?存檔的圖片若被裁切如何設定? bbox_inches = 'tight'Python如何讀取csv檔? csv.reader(f) , 如何計算IRR? numpy_financial.irr() 免費下載IRR計算機,如何寫入csv檔? csv.writer(f).writerows(2D List) ; if not os.path.exists(folder): os.makedirs(folder)
0 Python IDE(Integrated Development Environment 整合開發環境) colab如何掛載雲端硬碟?from google.colab import drive; drive.mount( ‘/content/drive’ ) ; 檔案複製shutil.copy() #shell utility; 檔案移動shutil.move( source_file, destination_path); 刪除整個資料夾shutil.rmtree( folder_to_delete ); 刪除某一個檔案os.remove() #shutil.remove()會觸發AttributeError; 如何將檔案路徑拆分為父資料夾與檔案名稱(含副檔名)? os.path.dirname( file_path) ; os.path.basename( file_path) 如何將檔案名稱拆分為主檔名與副檔名? os.path.splitext( file_name) #split(分裂) ext的意思 2023-07-16
0 Python: matplotlib如何設定座標軸刻度? plt.xticks(seq, labels) ;如何生成fig, ax物件? fig = plt.figure(figsize= (10.24, 7.68)) ; ax = fig.add_subplot() ; fig, ax = plt.subplots(figsize=(10.24, 7.68)) ; 如何使用中文? plt.rcParams[“font.family”] = [“Microsoft JhengHei”] 2023-02-08
0 Python 線性迴歸: 氣溫跟冰飲銷售量有關係嗎? LinearRegression ; from sklearn import linear_model ; regr = linear_model. LinearRegression() 2022-12-11
近期留言