@qqzj The problem that you will run into is that python doesn't exactly have this feature available. As @Boud mentions, the reference to tablea1, tableb1, tablec1 etc are lost after concatenation.
I'll illustrate a quick and dirty example of the workaround (which is very inefficient, but will get the job done).
Without your data, I'm basically creating random data frames.
tablea1 = pd.DataFrame(np.random.randn(10, 4))
tableb1 = pd.DataFrame(np.random.randn(10, 4))
tablec1 = pd.DataFrame(np.random.randn(10, 4))
tablea2 = pd.DataFrame(np.random.randn(10, 4))
tableb2 = pd.DataFrame(np.random.randn(10, 4))
tablec2 = pd.DataFrame(np.random.randn(10, 4))
Applying your code to iterate over this list
list_a = [tablea1, tablea2]
list_b = [tableb1, tableb2]
list_c = [tablec1, tablec2]
for i in range(len(list_a)):
list_a[i] = pd.concat([list_a[i], list_b[i], list_c[i]], axis=1)
Once you run a compare here, you see the issue that you have highlighted, namely that while list_a[i]
has been concatenated with tablea1
, tableb1
, and tablec1
, this hasn't been assigned back to tablea1
.
As I mentioned in the comment, the answer is to assign tablea1
with the list[0]
tablea1=list_a[0]
You would repeat this for tablea2
tablea3
etc.
Doing the compare, you can see now that tablea1 matches the values in list[0]
tablea1==list_a[0]
0 1 2 3 0 1 2 3 0 1 2 3
0 True True True True True True True True True True True True
1 True True True True True True True True True True True True
2 True True True True True True True True True True True True
3 True True True True True True True True True True True True
4 True True True True True True True True True True True True
5 True True True True True True True True True True True True
6 True True True True True True True True True True True True
7 True True True True True True True True True True True True
8 True True True True True True True True True True True True
9 True True True True True True True True True True True True
Again this is not the ideal solution, but what you are looking for doesn't seem to be the 'pythonic' way.