[英]How to append a list to dataframe without using column names?
I want to append a list of 4 prices [1,2,3,4] to an already existing dataframe using the dataframe.append() method, the already existing dataframe has four columns. 我想使用dataframe.append()方法将4个价格[1,2,3,4]的列表追加到一个已经存在的数据帧中,已经存在的数据帧有四列。
using this 使用这个
dataframe = pd.DataFrame(columns=["open", "high", "low", "close"], data = [[1,2,3,4]])
creates the dataframe 创建数据框
open high low close
0 1 2 3 4
then i want to append some lists like this: 然后我想附加一些像这样的列表:
dataframe = dataframe.append([[5,6,7,8]], ignore_index =True)
gives the output 给出输出
open high low close 0 1 2 3
0 1.0 2.0 3.0 4.0 NaN NaN NaN NaN
1 NaN NaN NaN NaN 5.0 6.0 7.0 8.0
while I want the list to be appended in continuation to the dataframe, is there a way to do this without using the column names, only the list of four prices? 虽然我希望列表可以连续地追加到数据帧中,但是有没有一种方法可以不使用列名而只使用四个价格列表呢?
你可以做类似的事情
df.loc[len(df)] = [1, 2, 3, 4]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.