代码之家  ›  专栏  ›  技术社区  ›  Nazim Kerimbekov Gusev Slava

如何将LabelBinarizer列添加到数据帧

  •  0
  • Nazim Kerimbekov Gusev Slava  · 技术社区  · 6 年前

    here are the first couple of rows of the CSV file that I'm using

    import pandas as pd
    from sklearn.preprocessing import LabelBinarizer
    #import matplotlib.pyplot as plot
    
    
    #--------------------------------
    
    label_conv = LabelBinarizer()
    appstore_original = pd.read_csv("AppleStore.csv")
    
    #--------------------------------
    
    lb_conv = label_conv.fit_transform(appstore["cont_rating"])
    column_names = label_conv.classes_
    
    print(column_names)        
    print(lb_conv)
    

    我得到了lb_conv和列名。因此:

    label_conv appstore_original column_names

    如果有人能帮忙,那就太好了。

    1 回复  |  直到 6 年前
        1
  •  1
  •   MaxU - stand with Ukraine    6 年前

    lb = LabelBinarizer()
    
    df = pd.read_csv("AppleStore.csv")
    
    df = df.join(pd.DataFrame(lb.fit_transform(df["cont_rating"]),
                              columns=lb.classes_, 
                              index=df.index))
    

    index=df.index