Skip to content Skip to sidebar Skip to footer

How To Automatically Fill Blank Column With None In Pandas

I have a info.txt file it looks like this: B 19960331 00100000 00000000000000 00000000000000 00000000000000 00000000 00000000000000 00000000000000 00000000000000 B 19960430 0009910

Solution 1:

This works, and should(?) be the same as reading the file from disk:

import pandas as pd
import io

my_file = io.StringIO("""B 19960331 00100000 00000000000000 00000000000000 00000000000000 00000000 00000000000000 00000000000000 00000000000000
B 19960430 00099100 00000000000000 00000000000000 00000000000000 00000000 00000000000000 00000000000000 00000000000000
B 19960531 00098500 00000000000000 00000000000000 00000000000000 00000000 00000000000000 00000000000000 00000000000000
B 19971000 20 31""")

df = pd.read_csv(my_file, sep="\s+", header=None)

output:

01234567890  B  1996033110000000.00.00.00.00.00.01  B  199604309910000.00.00.00.00.00.02  B  199605319850000.00.00.00.00.00.03  B  199710002031NaNNaNNaNNaNNaNNaN

Post a Comment for "How To Automatically Fill Blank Column With None In Pandas"