Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Include old pandas dataframe after merging

$
0
0

I'm using this code to generate a dataframe that is merged from many different files. However, the final dataframe doesn't have all the columns of the original dataframe, 'df'. Is there a way to include all the columns of 'df' in the final generated 'merged_data'?

import pathlibimport pandas as pdroot_path = pathlib.Path('root')  # use pathlib instead of os.pathdata = {}# use enumerate rather than create an external counterfor count, (_, row) in enumerate(df.iterrows(), 1):    folder_name = row['File ID'].strip()    file_name = row['File Name'].strip()    file_path = root_path / folder_name / file_name    folder_file_id = f'{folder_name}_{file_name}'    file_data = pd.read_csv(file_path, header=None, sep='\t',                            names=['Case', folder_file_id],                            memory_map=True, low_memory=False)    data[folder_file_id] = file_data.set_index('Case').squeeze()    print(count)merged_data = (pd.concat(data, names=['folder_file_id'])                 .unstack('Case').reset_index())

Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>