0
我有其中有一列中的下列值的列的熊貓數據幀:在大熊貓數據幀轉換列到多列
Identifier
[1;12;7;3;0]
[4;5;2;6;0]
我想在方括號中的數值轉換在此列5個新欄目。實質上,我想將這些值分成5個新列,同時保持新列的索引與原始列相同。
Identifier,a,b,c,d,e
[1;12;7;3;0],1,12,7,3,0
[4;5;2;6;0],4,5,2,6,0
pattern = re.compile(r'(\d+)')
for g in raw_data["Identifier"]:
new_id = raw_data.Identifier.str.findall(pattern) # this converts the Identifier into a list of the 5 values
raw_data.append({'a':new_id[0],'b':new_id[1],'c':new_id[2],'d':new_id[3],'d':new_id[4]}, ignore_index=True)
上面的代碼將從「標識符」列中提取的值添加到DataFrame的末尾而不是相應的行。我如何將提取的值添加到與原始列('標識符')相同的行/索引?
這是完美的。謝謝! – kkhatri99 2014-09-21 02:03:17