MASIGNASUKAv102
6510051498749449419

converting .data file to .csv using python

converting .data file to .csv using python
Add Comments
Tuesday, November 13, 2018


Datasets  are very essential part of data science. Simply you cannot go and create your own data using excel or someother ,ofcourse this would be better to increase skills & when you require data that doesnt support your model. Instead you find your data by some popular sources like

1. UCI
2.kaggle

Sometimes you may find the data in someother format like .data in this case . But you probably need a .csv file. There are different ways to do this.  But as a python lover you can use csv module to copy the files into csv format .


import csv

with open('sampledataset.data.txt') as input_file:
   lines = input_file.readlines()
   newLines = []
   for line in lines:
      newLine = line.strip().split()
      newLines.append( newLine )

with open('myset.csv', 'wb') as test_file:
   file_writer = csv.writer(test_file)
   file_writer.writerows( newLines )
Adarshreddy Adelli

As an Engineering Lead with deep expertise in Artificial Intelligence, Cybersecurity, and Systems Architecture, I guide teams in building innovative, secure, and scalable solutions.I am passionate about tackling challenging technical problems, fostering engineering excellence, and delivering solutions that balance innovation, security, and performance. I actively share knowledge through blogging and community engagement, contributing to the advancement of AI and cybersecurity practices.