python - Moving rows of data within pandas dataframe to end of last column -
python newbie, please gentle. have data in 2 "middle sections" of multiple excel spreadsheets isolate 1 pandas dataframe. below link data screenshot. within each file, headers in row 4 data in rows 5-15, columns b:o. headers , data continue headers on row 21, data in rows 22-30, columns b:l. move headers , data second set , append them end of first set of data.
this code captures header row 4 , data in columns b:o captures rows under header including second header , second set of data. how move second set of data , append after first set of data?
path =r'c:\users\sarah\desktop\original' allfiles = glob.glob(path + "/*.xls") frame = pd.dataframe() list_ = [] file_ in allfiles: df = pd.read_excel(file_,sheetname="data1", parse_cols="b:o",index_col=none, header=3, skip_rows=3 ) list_.append(df) frame = pd.concat(list_)
if of excel files have same number of rows , 1 time operation, hard code numbers in read_excel
. if not, little tricky, pretty follow same procedure:
for file_ in allfiles: top = pd.read_excel(file_, sheetname="data1", parse_cols="b:o", index_col=none, header=4, skip_rows=3, nrows=14) # note nrows kwag bot = pd.read_excel(file_, sheetname="data1", parse_cols="b:l", index_col=none, header=21, skip_rows=20, nrows=14) list_.append(top.join(bot, lsuffix='_t', rsuffix='_b'))
Comments
Post a Comment