AttributeError: 'Series' object has no attribute 'labelNames'

Hello. I have some matlab files containing some matrix (x1, x2,…) and a table (called labelNames). With the following code I’m trying to access to labelNames contained in the matlab files:

Folder = 'dataCubes/'
# Listing all .mat files contained in dataCubes folder; hence, put all mat
# files in one folder without subfolders
mat_files = glob(f'{Folder}/*.mat')
numberOfDbExamples = len(mat_files)
Data = {}
for i in range(0, numberOfDbExamples):
    Data[i] = read_mat(mat_files[i])
    my_df = pd.DataFrame(Data)
    newLabelNames, newMask = changeLabelNames(my_df[i].labelNames, my_df[i].mask)

changeLabelNames is a function I created to change some names contained in labelNames. But it seems that when I read the matlab files in python, the table labelNames is not present. Can you help me to find the problem?

This error is raised by pandas as the DataFrame doesn’t seem to contain the wanted attribute. Check the DataFrame content and make sure you are indexing it in the right way. Since this issue is unrelated to PyTorch you might get a faster and better answer in a pandas-specific discussion board.

I checked the content of the Dataframe and doesn’t seem to contain the table labelNames, do you have an idea of how to extract it?

If the DataFrame doesn’t contain the labelNames attribute you won’t be able to “extract” it and you would have to check why it’s missing and/or why you expect it to be there. Maybe you are loading the wrong DataFrame?

As @ptrblck has already stated, this is a pandas related question - Pandas documentation will be helpful.

As I can see, you’ve created a dataframe using a dictionary. Then you index it [i] which will yield columns (Series to be more specific). I don’t quite understand how you are trying to access its labelNames attribute that isn’t a pre-defined one for Series objects.

I think the problem is that the dataframe contains array data and a table (labelNames). I can load the array data correctly, while the table in the dataframe is called None. So the question is: how to read table correctly?