Python Forum
hierarchical MultIndex Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
hierarchical MultIndex Python
#1
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. [Image: j10m9.png.html]Thank you in advance.
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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Pandas hierarchical sum mariostg 1 378 Jan-26-2024, 03:47 PM
Last Post: mariostg
  Is there a hierarchical catalog of Anaconda libraries divided by the type of tasks? AlekseyPython 1 1,579 Nov-25-2020, 09:11 AM
Last Post: Larz60+
  Sklearn Agglomerative Hierarchical Clustering - help with array set up pstarrett 4 5,227 Feb-21-2017, 05:05 AM
Last Post: pstarrett

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020