Skip to content
Advertisement

How to return dataframe containing column names of multiple dataframe

I have multiple dataframes and would like a dataframe that contains all column names from said multiple dataframes.

For example :

JavaScript

I would like to get a dataframe like this :

JavaScript

Help would be very appreciated and thank you in advance!

Advertisement

Answer

If possible extract DataFrame names fom columns names use list comprehension with concat and last for new column in first position use DataFrame.insert with Series.str.extractSeries.str.extractall for values from columnsnames before _:

JavaScript

Similar ide with flatten list comprehension:

JavaScript

Alternative is create dictionary of DataFrames and in dict comprehension use concat, keys of dict create first level of MultiIndex, so not necessary parse columns names:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement