【发布时间】:2016-05-04 19:18:27
【问题描述】:
我有一个包含三个熊猫数据框的列表。所有 DataFrame 都具有确切的列名并具有相同的长度。我想比较每个 DataFrame 中特定列的所有条目。假设列表有:
List=[df1,df2,df3].
每个dataFrame都有以下结构。 df1 有结构
column1 column2 column3
4 3 4
4 5 7
7 6 6
8 6 4
df2 有结构
column1 column2 column3
4 3 4
7 5 7
7 6 5
8 6 4
df3 有结构
column1 column2 column3
4 3 5
4 1 7
7 6 6
8 6 4
我想将 df1 column1 和 column2(每行)的内容与包含 df2(column1 和 column2)和 df3(column1 和 column2)进行比较
我写了一些类似这样的想法:
for i in range(len(List)):# iterate through the list
for j in range(len(List[0].index.values)):# iterate through the the whole dataFrame
#I would like to so something like: if df1[column1][row1]=df2[column1][row1] then do ....
# now i dont know how to iterate through all the dataFrames simulatanously to compare the content of of column 1 and column 2(for each row k) of df1 with the content of column 1 and column 2 of df2 and column 1 and column 2 of df3.
我被困在那里
【问题讨论】:
标签: python python-2.7 pandas dataframe