How To Specify The Data Types Of A Column Name Without Any Headers In Pandas Data Frame?
I have text file without any header . While loading to DF in pandas few columns are loading as float which I want as string . For files with header I use to specify the Data types
Solution 1:
You can use column index.
a = "2,5,'adgh'\n4,2,'sgd'"
df = pd.read_csv(io.StringIO(a), header=None, dtype={0:str, 1:int, 2:str})
print(df.dtypes)
output:
0object1 int64
2object
dtype: object
Post a Comment for "How To Specify The Data Types Of A Column Name Without Any Headers In Pandas Data Frame?"