0

I have multiples of csv file. I have used regex and loop to read all of them to df and stored the dfs in a list. However, when I try to concat them, the result df appeared like this:

     A  B  C  D  E  F  G  H
    2     A   6   2      3.08      1.36  0.25     1.74     2.17
3     D   6   4      2.33      1.61  0.25     1.88     1.99
4     H   5   3      2.90      1.40  0.00     2.06     1.82
..   ..  ..  ..       ...       ...   ...      ...      ...
375   D   3   3      1.60      2.34  1.00     1.98     1.88
376   A   6   1      1.50      2.57 -1.00     1.95     1.92
377   H   4   6      1.63      2.30  1.50     1.90     1.97
378   D   6   3      2.03      1.80  0.25     1.77     2.12
379   D   6   4      1.57      2.40 -1.50     1.99     1.88

[380 rows x 8 columns],     A  B  C  D  E  F  G  H
0     H   1   9      2.68      1.47 -0.25     2.03     1.84
1     A   2   4      2.27      1.65  0.25     1.88     1.99
2     H   4   3      2.37      1.59  0.00     1.80     2.09
3     D   0   4      1.85      1.98  1.00     1.86     2.01
4     D   4   6      2.35      1.60  0.00     1.83     2.05

I don't know why the shape of df is included. The code is as follow:

list = []

for i in os.listdir(path):
    if re.match(regex,i):
        a = pd.read_csv(i)
        print(a)
        a.drop(a.columns.difference(remained_list), axis = 1, errors='ignore', inplace=True)
        list.append(a)

pd.concat(list,axis=1, ignore_index=True)
Man Wong
  • 9
  • 4

0 Answers0