7 4 3 3 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 pandas articles

[Python] Pandas DataFrame 如何顯示所有欄位

在使用 Python 的 Pandas DataFrame,如果要列出結果,顯示的行數只有 20 行。 import pandas as pd import numpy as np df = pd.DataFrame(np.random.randint(0, 26,size=(10, 26)), columns=list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')) df 修改參數為 None 之後,就會顯示所有的行數,不再只顯示 20 行。 pd.set_option("display.max.columns", None) df ……

Continue reading

使用 Pandas groupby 和 agg 合併資料

前因 想要把下面 dataframe , 分類後合併在一起 order devie abbr 0 first memory m 1 second cpu c 2 third disk d 3 first cpu c 成為下面的 data format order devie abbr 0 first memory, cpu [m, c] 1 second cpu [c] 2 third disk [d] 先建立兩個 lambda 變數 ​ f1 的功用是將 dataframe 轉換成字串, f2 則將 dataframe 轉換成 list >>>f1 = lambda x: ", ".join(x.dropna()) >>>f1(data.abbr) 'm, c, d, c' >>>f2 = lambda x: [z for y in x for z in y] >>>f2(data.……

Continue reading