Skip to content Skip to sidebar Skip to footer

Reading .data Files Using Pandas

Recently i encountered a file with .data extension and i searched google, i found irrelevant answers. I tried different solutions provided by blogs and websites. Nothing seems help

Solution 1:

The solution to read .data file using pandas is read_fwf(). For better knowledge refer read_fwf.

Example:

import pandas as pd
data = pd.read_fwf("example.data")

By default data will not contains columns because in .data will contain any columns. In order to get column names we have to pass the column names while reading the file.

Example:

import pandas as pd
data = pd.read_fwf("example.data", names=["col1", "col2"])
print(data.columns)
>>> [col1, col2]

Hope this is useful..!!!

Post a Comment for "Reading .data Files Using Pandas"