I want to split equal length string without the splitter and expand the dataframe.
Here is the test dataframe I am using:
sample1 = pd.DataFrame({
'TST': {1: 1535840000000, 2: 1535840000000},
'RCV': {1: 1535840000000, 2: 1535850000000},
'TCU': {1: 358272000000000, 2: 358272000000000},
'SPD': {1: '0', 2: '00000000000000710000007D007C00E2'}
})
As you can see, the SPD
column contains various length string without any splitter.
I want to split the SPD
column every 4 characters into new rows, then expand them to the dataframe.
TST RCV TCU SPD
0 1535840000000 1535840000000 358272000000000 0000
1 1535840000000 1535840000000 358272000000000 0000
2 1535840000000 1535840000000 358272000000000 0000
3 1535840000000 1535840000000 358272000000000 0071
4 1535840000000 1535840000000 358272000000000 0000
5 1535840000000 1535840000000 358272000000000 007D
6 1535840000000 1535840000000 358272000000000 007C
7 1535840000000 1535840000000 358272000000000 00E2
I tried to firstly generate a Series by using this:
pd.concat([pd.Series(re.findall('....', row['SPD'])) for _, row in sample1.iterrows()]).reset_index()
which gives
index 0
0 0 0000
1 1 0000
2 2 0000
3 3 0071
4 4 0000
5 5 007D
6 6 007C
7 7 00E2
But I could not expand it back the sample1