2018-05-01から1ヶ月間の記事一覧

【Python/Pandas】ピボットテーブル化と逆変換

pandas ver0.22 pd.pivotでピボットテーブルを作成。 pd.meltで逆の変換ができる。 コード全体は下記のとおり。 import pandas as pd df_pivot = pd.DataFrame([[101, 201, 301], [102, 202, 302], [103, 203, 303]], columns=['a', 'b', 'c'], index=['a', …

【Python】Pandasのデータフレームの要素に配列を代入したい

環境: python 3.6 pandas 0.22.0 画像のようなデータフレームを作りたいときのメモ。 下記のようにやればできる。 array_1d = np.ones(2) array_2d = np.ones([1, 2]) * 2 df.loc[0, 'obj'] = array_1d df.loc[[1], 'obj'] = [array_2d] #別解1 df['obj'] =…