Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open a .data file extension

I am working on side stuff where the data provided is in a .data file. How do I open a .data file to see what the data looks like and also how do I read from a .data file programmatically through python? I have Mac OSX

NOTE: The Data I am working with is for one of the KDD cup challenges

like image 356
Jason Donnald Avatar asked Aug 03 '15 21:08

Jason Donnald


2 Answers

Kindly try using Notepad or Gedit to check delimiters in the file (.data files are text files too). After you have confirmed this, then you can use the read_csv method in the Pandas library in python.

import pandas as pd
file_path = "~/AI/datasets/wine/wine.data"
# above .data file is comma delimited
wine_data = pd.read_csv(file_path, delimiter=",")
like image 152
mustious Avatar answered Sep 21 '22 04:09

mustious


It vastly depends on what is in it. It could be a binary file or it could be a text file.

If it is a text file then you can open it in the same way you open any file (f=open(filename,"r"))

If it is a binary file you can just add a "b" to the open command (open(filename,"rb")). There is an example here:

Reading binary file in Python and looping over each byte

Depending on the type of data in there, you might want to try passing it through a csv reader (csv python module) or an xml parsing library (an example of which is lxml)

After further into from above and looking at the page the format is:

Data Format The datasets use a format similar as that of the text export format from relational databases:

One header lines with the variables names One line per instance Separator tabulation between the values There are missing values (consecutive tabulations)

Therefore see this answer:

parsing a tab-separated file in Python

I would advise trying to process one line at a time rather than loading the whole file, but if you have the ram why not...

I suspect it doesnt open in sublime because the file is huge, but that is just a guess.

like image 21
user2539336 Avatar answered Sep 17 '22 04:09

user2539336