2017-04-24 14 views

答えて

3
df = pd.DataFrame({0: [['hello', 'motto'], ['motto', 'mania']]}) 
print(df) 

       0 
0 [hello, motto] 
1 [motto, mania] 

ここstr.get_dummies

df[0].str.join('|').str.get_dummies() 

    hello mania motto 
0  1  0  1 
1  0  1  1 
+0

はありがとうございました!私が許可されたら答えを受け入れるでしょう! – laila

+0

@laila大歓迎です。 – piRSquared

1

続い使用str.joinは、メモリ節約のソリューションですスパースマトリクスとPandas.SparseSeriesを使用しようとしている:

​​

結果:

In [81]: df 
Out[81]: 
    hello mania motto 
0  1  0  1 
1  0  1  1 

In [82]: df.memory_usage() 
Out[82]: 
Index 80 
hello  8 # notice memory usage: # of ones multiplied by 8 bytes (int64) 
mania  8 
motto 16 
dtype: int64 
関連する問題