【发布时间】:2021-06-17 15:24:36
【问题描述】:
我正在尝试将下面的列表附加到空数据框的第一行。
to_append = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
df_length = len(df_b)
df_b.loc[df_length] = to_append
空数据框的列数多于列表可分配给的列数
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
当我使用上面的代码时,我得到一个错误
ValueError: cannot set a row with mismatched columns
如何附加列表以获得这样的结果?
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
0 1 2 3 4 5 6 7 8 9 10
【问题讨论】:
标签: python pandas list dataframe