Create a sub columns in the dataframe using a another dataframe

前端 未结 3 465
粉色の甜心
粉色の甜心 2021-01-29 03:41

I am new to the python and pandas. Here, I have a following dataframe .

did           features   offset   word   JAPE_feature  manual_feature 
0             200          


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-29 04:25

    Less fancy solution, but maybe easier to understand:

    First of all put the features that will decide which feature you choose on each row in a list called for example list_features.

    Then:

    # List all the features possible and create an empty df
    feat = [100,200,2200,2600,156,162,4600,100]
    df_final= pd.DataFrame({x:[] for x in feat})
    
    # Fill the df little by little
    for x in list_features:
        df_final = df_final.append({y:1 if x==y else 0 for y in feat }, ignore_index=True)
    

提交回复
热议问题