I'm trying to read a fixed width file using pandas.read_fwf, and please see a sample of the file as below:
0000123456700123
0001234567800045
Say, column 0-11 is the balance (with format %12.2f), and column 11-16 is the interest rate (with format %6.2f). So my expected output data frame should look like this:
Balance Int_Rate
0 12345.67 1.23
1 123456.78 0.45
Here's my code for reading the file without formatting:
colspecs = [(0,11),(11,16)]
header = ['Balance','Int_Rate']
df = pd.read_fwf("dataset",colspecs=colspecs, names=header)
I've checked the documentation of pandas.read_fwf, however it seems impossible to format the columns as an option during the importing process. Do I have to update the formats afterwards, or there's a better way to do it?