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.
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")
df = pd.read_table("adults.data")
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
This might helps you
- Before loading the data make sure check the file format.
- Load the required libraries
- First read the excel file using 'pd.read' function save the file into csv format using function 'to_csv'
pp = pd.read_excel('paul_palmer.xlsx') pp.to_csv('paul_palmer.csv', index=False)