我有一个名为cars的数据框。我想用brand列的第一个元素创建一个名为Brand_name的新列,但我不断收到错误消息“ list index out of range”(列表索引超出范围)
cars = Brand Units_sold
[Toyota] 87
[Acura] 99
[Toyota, Ford, GMC] 87
[Kia, Honda] 25
[Honda] 109
[Mercedes, Bugatti] 76
......
这就是我要实现的目标
cars = Brand Units_sold Brand_name
[Toyota] 87 [Toyota]
[Acura] 99 [Acura]
[Ford,Toyota, GMC] 87 [Ford]
[Kia, Honda] 25 [Kia]
[Honda] 109 [Honda]
[Mercedes, Bugatti] 76 [Mercedes]
....
这是我应用的代码
cars['Brand_name'] = cars['Brand'].apply(lambda x: x[0])