Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/306.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.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 从多个列表创建数据帧_Python_Pandas - Fatal编程技术网

Python 从多个列表创建数据帧

Python 从多个列表创建数据帧,python,pandas,Python,Pandas,我有几个清单: a = [1, 2, 3, 4] b = [5, 6, 7, 8] c = [7, 8, 9, 10] 我想要一个数据框,其中有3列使用列表名称自动命名 a b c 1 5 7 2 6 8 3 7 9 4 8 10 如何做到这一点?谢谢。您可以使用以下代码从列表中创建熊猫数据帧: import pandas as pd a = [1, 2, 3, 4] b = [5, 6, 7, 8] c = [7, 8, 9, 10] df = pd.DataFrame(list(zi

我有几个清单:

a = [1, 2, 3, 4]
b = [5, 6, 7, 8]
c = [7, 8, 9, 10]
我想要一个数据框,其中有3列使用列表名称自动命名

a b c
1 5 7
2 6 8
3 7 9
4 8 10

如何做到这一点?谢谢。

您可以使用以下代码从列表中创建熊猫数据帧:

import pandas as pd

a = [1, 2, 3, 4]
b = [5, 6, 7, 8]
c = [7, 8, 9, 10]

df = pd.DataFrame(list(zip(a, b, c)),
                  columns =['a', 'b', 'c'])

print(df)

希望这有帮助

有没有一种方法可以自动命名列,因为有许多长名称的列表?感谢'columns'参数就是这个参数如果你想让字符串“名称”与列表关联,你应该首先构建一个
dict
,而不是单独命名的列表。