Source Data:
20 7369 CLERK
30 7499 SALESMAN
30 7521 SALESMAN
20 7566 MANAGER
30 7654 SALESMAN
30 7698 MANAGER
10 7782 MANAGER
20 7788 ANALYST
10 7839 PRESIDENT
30 7844 SALESMAN
20 7876 CLERK
30 7900 CLERK
20 7902 ANALYST
Requirement:
012345678901234567890123456789
Hi All,
I am reading this .dat file data into python pandas successfully. Left to right length of the data in a row is 30 (012345678901234567890123456789) My requirement is, I need to derive 3 columns
From left to right: 1 to 4 (length 4) spaces as DEPTNO
From left to right: 5 to 13 (length 9) spaces as EMPNO
From left to right: 14 to 30 (length 9) spaces as EMPNO
I tried this code:
import pandas as pd
with open('Emp.dat','r') as f:
next(f) # skip first row
df = pd.DataFrame(l.rstrip().split() for l in f)
Required Output:
DEPTNO EMPNO JOB
20 7369 CLERK
30 7499 SALESMAN
30 7521 SALESMAN
20 7566 MANAGER
30 7654 SALESMAN
30 7698 MANAGER
10 7782 MANAGER
20 7788 ANALYST
10 7839 PRESIDENT
30 7844 SALESMAN
20 7876 CLERK
30 7900 CLERK
20 7902 ANALYST