![](/img/trans.png)
[英]Get columns names from one data frame and add them as empty columns in another data frame in pandas
[英]pandas: Add row from one data frame to another data frame?
我有两个具有相同列标题的数据帧。
我正在迭代df1中的行,拆分其中一列,然后使用这些拆分列创建多行以添加到另一个数据帧。
for index, row in df1.iterrows():
curr_awards = row['AWARD'].split(" ")
for award in curr_awards:
new_line = row
new_line['AWARD'] = award.strip()
#insert code here to add new_line to df2
将行添加到另一个数据框的pandas方法是什么?
我想到了。
for index, row in df1.iterrows():
curr_awards = row['AWARD'].split(" ")
for award in curr_awards:
new_line = row
new_line['AWARD'] = award.strip()
df2.loc[len(df2)] = new_line
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.