資料轉換


lis_straw_hat_age = [19, 21, 20, 19, 21, 17, 30, 36, 90]
lis_straw_hat_height = [174, 181, 170, 176, 180, 90, 188, 240, 277]
lis_straw_hat_gender = ['male', 'male', 'female', 'male', 'male', 'male', 'female', 'male', 'male']
dict_straw_hat_info = {'age': lis_straw_hat_age,
                       'height': lis_straw_hat_height,
                       'gender': lis_straw_hat_gender}

#使用DataFrame函數,把字典直接轉換成DataFrame
df_straw_hat_info = pd.DataFrame(dict_straw_hat_info) 

df_straw_hat_info

lis_devil_fruit = [['橡膠果實', '蒙其·D·魯夫'],
                   ['人人果實', '多尼多尼·喬巴'],
                   ['花花果實', '妮可·羅賓'],
                   ['黃泉果實', '布魯克'],
                   ['黑暗果實', '馬歇爾·D·汀奇'],
                   ['震動果實', '馬歇爾·D·汀奇']]

#使用DataFrame函數,把列表直接轉換成DataFrame,並加上參數columns,將DataFrame的columns取名
df_devil_fruit = pd.DataFrame(lis_devil_fruit, columns=['devil_fruit', 'name']) 

df_devil_fruit

results matching ""

    No results matching ""