Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python熊猫:将列表添加到不同len的df_Python_Pandas_List_Dataframe - Fatal编程技术网

Python熊猫:将列表添加到不同len的df

Python熊猫:将列表添加到不同len的df,python,pandas,list,dataframe,Python,Pandas,List,Dataframe,我有len 52的以下列表: cw = list(range(1,53)) 我想将此列表添加到len 104的df中 我使用: df.insert(0,"CW",cw, True) 这导致: ValueError: Length of values does not match length of index 我希望将列表添加到df的前52行,然后从1开始添加到第二52行。您可以通过添加+cw来更改代码: df.insert(0,"CW",cw+cw, True) 或通过添加*2: df

我有len 52的以下列表:

cw = list(range(1,53))
我想将此列表添加到len 104的df中

我使用:

df.insert(0,"CW",cw, True)
这导致:

ValueError: Length of values does not match length of index

我希望将列表添加到df的前52行,然后从1开始添加到第二52行。

您可以通过添加
+cw
来更改代码:

df.insert(0,"CW",cw+cw, True)
或通过添加
*2

df.insert(0,"CW",cw * 2, True)

您可以通过添加
+cw
来更改代码:

df.insert(0,"CW",cw+cw, True)
或通过添加
*2

df.insert(0,"CW",cw * 2, True)

您可以更改列表的定义:
cw=list(range(1,53))+list(range(1,53))
甚至:
cw=list(range(1,53))*2
df.insert(0,“cw”,cw*2,True)
您可以更改列表的定义:
cw=list(range(1,53))+list(range(1,53))
甚至:
cw=list(range(1,53))*2
df.插入(0,“CW”,CW*2,真)