LoginSignup
16
17

More than 5 years have passed since last update.

Python pandas覚書

Last updated at Posted at 2017-09-21

Series型からDataframeへの変換

Dataframeを1行ずつ取り出してSeries型に変換し、インデックスを0,1,2,3と降り直す。
(次の例では1行のみなのでインデックスを0としたい)

for key,row in dataframe1.iterrows():        
    dataframe2 = row.to_frame().T.reset_index()

Dataframeの転置

dataframe1.T

Azure Machine Leanirngネタ

dict から dataframe に変換する時

pd.DataFrame.from_dict(dic)

したら、以下のエラーが出てしまった。
ValueError: If using all scalar values, you must pass an index

コンストラクタを使うように変更してもだめ。

#こちらはエラーになる
pd.DataFrame(dic)

DataFrameのオプションにindexを追加したら動作するようになった

#これで動くようになる。
pd.DataFrame(dic,index=['i',])
16
17
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
17