I have a dataframe that looks like this:
ACCEPTANCES_EXECUTED_FOR_ACCT____OUT ACCUMULATED_OTH_COMPREHENSIVE_INCOME ALLL_AMT AUDIT_INDICATOR AVAILABLE_FOR_SALE_SECURITIES COMMON_STOCK file
$- $- $979.00 $1.00 $- $1,200.00 FFIEC CDR Call Schedule RC0 03312001.txt
$- $93.00 $127.00 $4.00 $8,546.00 $120.00 FFIEC CDR Call Schedule RC0 03312001.txt
$- $246.00 $278.00 $1.00 $27,398.00 $- FFIEC CDR Call Schedule RC0 03312002.txt
$- $19.00 $130.00 $4.00 $4,047.00 $25.00 FFIEC CDR Call Schedule RC0 03312002.txt
$- $125.00 $1,188.00 $1.00 $21,265.00 $596.00 FFIEC CDR Call Schedule RC0 03312002.txt
$- $- $164.00 $4.00 $- $60.00 FFIEC CDR Call Schedule RC0 03312002.txt
$- $800.00 $2,115.00 $1.00 $55,699.00 $5,400.00 FFIEC CDR Call Schedule RC0 03312003.txt
$- $199.00 $2,372.00 $2.00 $32,306.00 $19.00 FFIEC CDR Call Schedule RC0 03312003.txt
$- $174.00 $1,114.00 $5.00 $18,296.00 $1,600.00 FFIEC CDR Call Schedule RC0 03312004.txt
$- $31.00 $323.00 $5.00 $2,997.00 $240.00 FFIEC CDR Call Schedule RC0 03312004.txt
How can I pivot the data so it looks like this?
Code Schedule Line Item Q12001 Q22002 Q32003 Q42004
RC0 BalanceSheet ACCEPTANCES_EXECUTED_FOR_ACCT____OUT $- $- $- $-
RC0 BalanceSheet ACCUMULATED_OTH_COMPREHENSIVE_INCOME $93.00 390 $999.00 $205.00
RC0 BalanceSheet ALLL_AMT $1,060.00 $1,760.00 $4,487.00 $1,437.00
RC0 BalanceSheet AUDIT_INDICATOR $5.00 $10.00 $3.00 $10.00
RC0 BalanceSheet AVAILABLE_FOR_SALE_SECURITIES $8,546.00 $52,710.00 $88,050.00 $21,293.00
RC0 BalanceSheet COMMON_STOCK $1,320.00 $681.00 $5,419.00 $1,840.00
I don't see this this is a standard pivot exercise, because I need to parse the file name into quarters and years, so this: 'FFIEC CDR Call Schedule RC0 03312001.txt'
Becomes this: 'Q12001'
- I would like to add in 'Line Item' as a header
- I would like the very first column to have a header of 'Code' and below this should be the name of the file, which is 'RC0'.
- I would like to add
It almost looks something like this...
output = df_append.pivot(index='headers', columns='file')
print(output)
But, of course there is no column named 'headers' and I can't figure out how to parse the file into quarters and years. There are over 100 fields in this dataframe and the 'file' goes back almost 20 years, split into quarters and years. Is this even possible?!