Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/361.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个 列表,其中一个将是主列表。列表1/列表2将合并在一起 与列表3/列表4相同。列表1/列表3索引将在中提供 主列表。List2/List4需要与中的适当索引匹配 主目录 输出: 预期产出: IIUCset_index在concat pd.concat([df.set_index('Area'), df1.set_index('Area'), df2.set_index('Area')],1).reset_index() Out[312]: in

我需要将列表与适当的索引单独匹配。有5个 列表,其中一个将是主列表。列表1/列表2将合并在一起 与列表3/列表4相同。列表1/列表3索引将在中提供 主列表。List2/List4需要与中的适当索引匹配 主目录

输出:

预期产出:


IIUC
set_index
concat

pd.concat([df.set_index('Area'), df1.set_index('Area'), df2.set_index('Area')],1).reset_index()
Out[312]: 
     index Content   cont
0    chera    hill    NaN
1  coonoor    hill    NaN
2    coorg     NaN    NaN
3     hima     NaN  mount
4   munnar     NaN    NaN
5   nilgri     NaN  mount
6     ooty    hill  mount
7  wayanad     NaN    NaN

看起来第一列的标题已更改为“索引”。我们能得到所需的标题吗?@selvamamamemuthu.reset_index()
       Area Content   cont
0    munnar     NaN    NaN
1      ooty     NaN    NaN
2   coonoor     NaN    NaN
3    nilgri     NaN    NaN
4   wayanad     NaN    NaN
5     coorg     NaN    NaN
6     chera     NaN    NaN
7      hima     NaN    NaN
8      ooty    hill    NaN
9   coonoor    hill    NaN
10    chera    hill    NaN
11   nilgri     NaN  mount
12     hima     NaN  mount
13     ooty     NaN  mount
       Area Content   cont
0    munnar     NaN    NaN
1      ooty     hill   mount
2   coonoor     hill   NaN
3    nilgri     NaN    mount
4   wayanad     NaN    NaN
5     coorg     NaN    NaN
6     chera     hill   NaN
7      hima     NaN    mount
pd.concat([df.set_index('Area'), df1.set_index('Area'), df2.set_index('Area')],1).reset_index()
Out[312]: 
     index Content   cont
0    chera    hill    NaN
1  coonoor    hill    NaN
2    coorg     NaN    NaN
3     hima     NaN  mount
4   munnar     NaN    NaN
5   nilgri     NaN  mount
6     ooty    hill  mount
7  wayanad     NaN    NaN