0
$\begingroup$

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.

$\endgroup$
1
0
$\begingroup$
  • 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")
    
$\endgroup$
1
  • $\begingroup$ Glad to help @paul-palmer if this or any answer has solved your question please consider accepting it by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. Kindly follow stackoverflow norms $\endgroup$ Jul 11 at 7:51
0
$\begingroup$

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

$\endgroup$
0
$\begingroup$

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)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.