Jan-01-2018, 09:59 PM
Hi guys, I am new to python and hopefully could add my code here right. I try to do the following:
I want to read multiple txt files and later concate them to a pandas dataframe. The files are like 15000 rows and 4 columns with float numbers. I have like 100 files in total and want to have the access to each of them by an index and as well as I want to count the rows in the files as an index.
I did the following coding, reading is working but I have 2 main problems. 1) Isaw reading the names of the columns each time does not make sense and also takes time. How can I change the name of the columns in the end ? 2) how can I multiIndex the table that I have on the outside the filenumber or my "datapoints" and inside the row-numbers ? With my solution right now I just can count "numbers". I included a photo to get a better idea of what am I trying to do.
Thank you in advance.
I want to read multiple txt files and later concate them to a pandas dataframe. The files are like 15000 rows and 4 columns with float numbers. I have like 100 files in total and want to have the access to each of them by an index and as well as I want to count the rows in the files as an index.
I did the following coding, reading is working but I have 2 main problems. 1) Isaw reading the names of the columns each time does not make sense and also takes time. How can I change the name of the columns in the end ? 2) how can I multiIndex the table that I have on the outside the filenumber or my "datapoints" and inside the row-numbers ? With my solution right now I just can count "numbers". I included a photo to get a better idea of what am I trying to do.
![[Image: j10m9.png.html]](https://picload.org/view/ddacoori/j10m9.png.html)
all_data = pd.DataFrame() #import all datas from test1 for f in glob.glob("mypathatmycomputer*"): df = pd.read_table(f, delim_whitespace=True, names=('A', 'B', 'C', 'D'), dtype={'A': np.float32, 'B': np.float32, 'C': np.float32, 'D': np.float32}) all_data=all_data.append(df,ignore_index=True) all_data.index.names = ["numbers"] print(all_data)