Bottom Page

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. İmage
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)
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Sklearn Agglomerative Hierarchical Clustering - help with array set up pstarrett 4 1,989 Feb-21-2017, 05:05 AM
Last Post: pstarrett

Forum Jump:


Users browsing this thread: 1 Guest(s)