Pasindu Perera
Pasindu Perera

Reputation: 587

format .csv file into new rows and columns

I have a .csv file that has (45211rows, 1columns). but i need to create new .scv file with (45211rows, 17columns)

These are the column names age;"job";"marital";"education";"default";"balance";"housing";"loan";"contact";"day";"month";"duration";"campaign";"pdays";"previous";"poutcome";"y"

I add a screenshot of the .csv file that I already have. enter image description here

Upvotes: 0

Views: 1085

Answers (2)

Ehab Ibrahim
Ehab Ibrahim

Reputation: 569

In pandas, the read_csv method has an option for setting the separator, which is , by default. To override, you can:

pandas.read_csv(<PATH_TO_CSV_FILE>, sep=';', header=0)

This will return a new dataframe with the correct format. The header=0 might not be needed, but it will force the returned dataframe to read the first line of the CSV file as column headers

Upvotes: 1

NBS
NBS

Reputation: 81

  1. Open the CSV in Excel
  2. Select all the data
  3. Choose the Data tab atop the ribbon.
  4. Select Text to Columns.
  5. Ensure Delimited is selected and click Next.
  6. Clear each box in the Delimiters section and instead choose Semi Colon.
  7. Click Finish.

Upvotes: 0

Related Questions