1
我有以下的数据帧:快速分离行
import pandas as pd
df = pd.DataFrame({'Probes':["1415693_at","1415693_at"],
'Genes':["Canx","LOC101056688 /// Wars "],
'cv_filter':[ 0.134,0.290],
'Organ' :["LN","LV"]} )
df = df[["Probes","Genes","cv_filter","Organ"]]
它看起来像这样:
In [16]: df
Out[16]:
Probes Genes cv_filter Organ
0 1415693_at Canx 0.134 LN
1 1415693_at LOC101056688 /// Wars 0.290 LV
我想要做的就是拆分行基于其中条目 的基因列由'///'分隔。
我希望得到的结果是
Probes Genes cv_filter Organ
0 1415693_at Canx 0.134 LN
1 1415693_at LOC101056688 0.290 LV
2 1415693_at Wars 0.290 LV
我总共有15万〜行检查。有没有一种快速的方法来处理?
为什么不'DF [ '基因'] str.split( '///',扩大= True).stack()'而不是'df ['Genes']。str.split('///')。apply(pd.Series,1).stack()'。它快了两倍 –
@AntonProtopopov - 谢谢。我将它添加到我的答案中作为替代解决方案(只比DataFrame构造函数慢一点点)。 – jezrael
对于那个解决方案你的's'是没有多索引的DataFrame .. –