I have a text file with header containing the column names in the following format along with data for the corresponding values in next row(s).

"ID"|"ACTUALCOST"|"UPDATEDCOST"|"CREATEDBYID"|"ENDDATE"

I am trying to read the file, add 2 attributes, extract values from header, split them and load them transposed into a dataframe. i.e my output to look like the image attached

enter image description here

With below code, I am able to read the file and copy it to a dataframe (I guess)

srcfile = pd.read_csv(filename,sep='|')
print('SOURCE FILE \n',srcfile)
col_names = srcfile.replace('"','')
for col_name in col_names:
    additional_col = []
    additional_col.append(col_name)
    additional_col.append('string')
print('UPDATED SOURCE FILE\n',col_names)

And this is what I am getting:

SOURCE FILE
Empty DataFrame
Columns: [ID,ACTUALCOST,UPDATEDCOST,CREATEDBYID,ENDDATE]
Index=[ ]
[0 rows x 5 columns]

UPDATED SOURCE FILE
Empty DataFrame
Columns: [ID,ACTUALCOST,UPDATEDCOST,CREATEDBYID,ENDDATE]
Index=[ ]
[0 rows x 5 columns]

0 Answers