I have a single text file that looks like:
Filename and date
Header1 Header2 Header3
data data data
data data data
data data data
Filename2 and date2
Header1 Header2 Header3
data data data
data data data
..and so on for many blocks of data.
I am using pd.read_csv to open the file.
How do I split this into separate dataframes? The headers for each dataframe will be identical, but the "filename and date" need to be preserved for each one. Also, there is a different number of lines of data for each file.
Used
dfs = {
k: pd.read_csv(pd.io.common.StringIO('\n'.join(dat)),delim_whitespace=True)
for k, *dat in map(str.splitlines, open('my.csv').read().split('\n\n'))
}
but am getting
Header1 Header2 Header3
Filename and date 0 data data data
1 data data data
2 data data data
Filename2 and date2
1 data data data
2 data data data
where "Filename2" "and" "date"2 are placed under the "Header1" "Header2" "Header3" columns like they are all part of 1 dataframe in 1 dict instead of making several different dataframes in the dict.