TransWikia.com

Convert .data file to .csv

Data Science Asked by Paul palmer on July 22, 2021

I’m using a data called ‘adults.data’, I need to work with that data as a ‘.csv’ file. Can anyone guide me on how can I change the format?
I tried opening the file in excel and then save it as csv, but the new file contains only one column containing all the ‘.data’ columns.

3 Answers

  • One way is to convert .data file to excel/csv using Microsoft Excel which provides an option to get external data (use Data tab --> from Text). Check this video for demo

  • Other way you can utilize python to read .data files and directly work with dataframes

         import pandas as pd
         df = pd.read_csv("adults.data")
    

    (OR)

         df = pd.read_table("adults.data")
    

Correct answer by Archana David on July 22, 2021

Another solution is to use pandas to read the file and then export it to an excel form as following:

import pandas as pd
df = pd.read_csv("file.data", sep=",", header=None)
df.to_excel("output.xlsx")  

You could read more here

Answered by Hamzawi on July 22, 2021

This might helps you

  1. Before loading the data make sure check the file format.
  2. Load the required libraries
  3. First read the excel file using 'pd.read' function save the file into csv format using function 'to_csv'

. example:

pp = pd.read_excel('paul_palmer.xlsx')


pp.to_csv('paul_palmer.csv', index=False)

Answered by HARI on July 22, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP