Python Forum
Cut .csv to pieces and save as .csv
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cut .csv to pieces and save as .csv
#1
Hi folks!   Cool 

I am quite new to programming / python - the journey is fun but can be frustrating at times...

I have a .csv file about 300 columns. The first column has the date. The following columns contain my Objects.
I want to create separate .csv files with two columns: 1. Date;  2. Object 

I want to tell Python:
Always take column 1 and one object-column and generate a .csv file from those two columns.
Then take column 1 (date) again and move on to the next object-column and generate the next .csv file.
Name the files after their object column.

So far i've got this:
import csv
object = 0

f = open("/home/myComputer/Data/data.csv")

csv_f = csv.reader(f, delimiter=';', quotechar='|')

writer = csv.writer(csv_f)

for row in csv_f:
   writer("[0],[object]")

   object += 1

f.close()
Thank you very much for your help on this! Pray
(If I don't solve the problem I will have to do this by hand with excel - which gives me the creeps)
Reply


Messages In This Thread
Cut .csv to pieces and save as .csv - by BruderKellermeister - Feb-13-2017, 09:10 AM
RE: Cut .csv to pieces and save as .csv - by wavic - Feb-13-2017, 09:29 AM
RE: Cut .csv to pieces and save as .csv - by merlem - Feb-13-2017, 09:48 AM
RE: Cut .csv to pieces and save as .csv - by buran - Feb-13-2017, 09:31 AM
RE: Cut .csv to pieces and save as .csv - by wavic - Feb-13-2017, 10:13 AM
RE: Cut .csv to pieces and save as .csv - by merlem - Feb-13-2017, 11:14 AM
RE: Cut .csv to pieces and save as .csv - by merlem - Feb-13-2017, 12:54 PM
RE: Cut .csv to pieces and save as .csv - by buran - Feb-13-2017, 03:05 PM
RE: Cut .csv to pieces and save as .csv - by merlem - Feb-13-2017, 08:15 PM
RE: Cut .csv to pieces and save as .csv - by buran - Feb-15-2017, 04:34 PM
RE: Cut .csv to pieces and save as .csv - by buran - Feb-16-2017, 11:03 AM
RE: Cut .csv to pieces and save as .csv - by buran - Feb-16-2017, 12:11 PM
RE: Cut .csv to pieces and save as .csv - by merlem - Feb-16-2017, 12:22 PM
RE: Converting a bunch of .csv to .txt - by buran - May-04-2017, 10:31 AM
RE: Converting a bunch of .csv to .txt - by buran - May-04-2017, 12:12 PM
RE: Converting a bunch of .csv to .txt - by Kebap - May-04-2017, 12:34 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020