Trying to use pandas read_fwf, but in my case I have start position named position in the json and column-size having size and I want to use fill values from flatfile in to the multiple columns from the same position. Below is the sample json and flatfile and expected output.
Sample Json:
"copybook": {
"item": [
{
"column-size": 3,
"position": 1,
"column-name": "SAMPLE_1",
"column-type": "STRING"
},
{
"column-size": 3,
"position": 4,
"column-name": "COL_2",
"column-type": "STRING"
},
{
"redefines": "COL_2",
"item": [
{
"column-size": 2,
"position": 4,
"column-name": "COL_3",
"column-type": "INT"
},
{
"column-size": 1,
"position": 6,
"column-name": "COL_4",
"column-type": "STRING"
}
]
}
]
}
}```
Sample Data is CCCRRR
expected output is
SAMPLEE_1 COL_2 COL_3 COL_4
CCC RRR RR R
Let's assume sample data is ABCDEF. If you want ABC/DEF/int(DE)/F, you can do:
NB. I assumed no header, but change the code if this is incorrect