閉じる

リストからDataFrameを生成[Pandas]

import numpy as np
import pandas as pd

if __name__ == "__main__":
    
    c1 = ["January", "September", "September", "November", "February"]
    c2 = ["UK", "Spain", "Jamaica", "Italy", "France"]
    c3 = [27, 28, 28, 22, 19]
    c4 = ["f", "f", "f", "f", "f"]
    
    df = pd.DataFrame([c1, c2, c3, c4]).T
    df.columns = ["Birth Month", "Origin", "Age", "Gender"]
    df.index = ["Carly", "Rachel", "Nicky", "Wendy", "Judith"]
    
    print(df)

Output

       Birth Month   Origin Age Gender
Carly      January       UK  27      f
Rachel   September    Spain  28      f
Nicky    September  Jamaica  28      f
Wendy     November    Italy  22      f
Judith    February   France  19      f

Pocket

コメントを残す

あなたのメールアドレスは公開されません。必須項目には印がついています *

© 2020 CV・NLP TIPS | WordPress Theme: Annina Free by CrestaProject.