尝试使用 pandas read_fwf,但在我的情况下,我在 json 中有名为 position 的起始位置,并且 column-size 具有大小,我想使用来自 flatfile 的填充值到来自同一位置的多个列。下面是示例 json 和平面文件以及预期输出。
示例 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