Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/281.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 使用for list指定变量名_Python_Pandas - Fatal编程技术网

Python 使用for list指定变量名

Python 使用for list指定变量名,python,pandas,Python,Pandas,有点简单的问题。我想遍历两个列表,第一个是命名变量,第二个是读取csv。我想根据列表遍历的名称将csv分配给变量 以下是我编写的代码示例: lists = ['one','two','three','four','five','six','seven','eight'] for i in lists: for j in range(1,9): i = merger(path,path_2,j) 在这种情况下,我没有将列表中的项目分配给变量I(作为变量名) 函数merge

有点简单的问题。我想遍历两个列表,第一个是命名变量,第二个是读取csv。我想根据列表遍历的名称将csv分配给变量

以下是我编写的代码示例:

lists = ['one','two','three','four','five','six','seven','eight']
for i in lists:
    for j in range(1,9):
        i = merger(path,path_2,j)
在这种情况下,我没有将列表中的项目分配给变量I(作为变量名)


函数merge仅采用两条路径,从每条路径读取CSV,并使用pd.concat将其合并。此问题已得到回答。然而,
exec
并不总是非常有效

你应该考虑使用字典,把名字作为键。< /P>
list=['1','2','3','4','5','6','7','8']
csv={}
对于列表中的i:
对于范围(1,9)内的j:
csv[i]=合并(路径,路径2,j)

这个问题已经得到了回答。然而,
exec
并不总是非常有效

你应该考虑使用字典,把名字作为键。< /P>
list=['1','2','3','4','5','6','7','8']
csv={}
对于列表中的i:
对于范围(1,9)内的j:
csv[i]=合并(路径,路径2,j)

python
中不太可能。使用如下字典:
csv\u dict={}
然后在循环中:
csv\u dict[i]=merge(path,path\u 2,j)
python
中实际上不可能。使用如下字典:
csv_dict={}
然后在循环中:
csv_dict[i]=merge(path,path_2,j)