Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/300.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,如果我有5个不同变量的单独列表,如下所示。如何将它们转换为数据帧 a = [1.4, 1.3] b = [0.8, 0.8] c = [2.4, 1.6] d = [3.6, 2.9] e = [2.8, 2.5] 预期数据帧 x,y 1.4, 1.3 0.8, 0.8 2.4, 1.6 3.6, 2.9 2.8, 2.5 使用pd.DataFrame将列表转换为df: ls = [[1.4, 1.3], [0.8, 0.8], [2.4, 1.6], [

如果我有5个不同变量的单独列表,如下所示。如何将它们转换为数据帧

a = [1.4, 1.3]
b = [0.8, 0.8]
c = [2.4, 1.6]
d = [3.6, 2.9]
e = [2.8, 2.5]
预期数据帧

x,y
1.4, 1.3
0.8, 0.8
2.4, 1.6
3.6, 2.9
2.8, 2.5

使用pd.DataFrame将列表转换为df:

ls = [[1.4, 1.3],
      [0.8, 0.8],
      [2.4, 1.6],
      [3.6, 2.9],
      [2.8, 2.5]]

df = pd.DataFrame(ls,columns=['x','y'])
以下是如何:

import pandas as pd

df = [[1.4, 1.3],
      [0.8, 0.8],
      [2.4, 1.6],
      [3.6, 2.9],
      [2.8, 2.5]]

df = pd.DataFrame(df, columns=['x', 'y']).to_string(index=False)

print(df)
输出:

   x    y
 1.4  1.3
 0.8  0.8
 2.4  1.6
 3.6  2.9
 2.8  2.5

这个问题需要更多的细节,这些列表是单独的变量还是列表的列表?@Erfan。这些是不同变量中的列表