0

I used cloudSim and CloudReports simulators for an experiment and i got my results into a raw data file rawData.CRD. Now I want to convert it to a csv file so that I can import it into RStudio for further analysis.

I followed this script.

import csv
import itertools
with open('rawData.CRD', 'r') as in_file:
    stripped = (line.strip() for line in in_file)
    lines = (line for line in stripped if line)
    grouped = itertools.izip(*[lines] * 3)
    with open('extracted.csv', 'w') as out_file:
        writer = csv.writer(out_file)
        writer.writerow(('title', 'intro', 'tagline'))
        writer.writerows(grouped)

It is creating a .csv file with all single row. But I want each values in seperate cells (when opened in Excel).

This is how my input raw file looks like from the simulator.

input raw file

and this is what I get after applying the script, all data as single element.

output csv

Please Help me to modify the script.

Jongware
  • 22,200
  • 8
  • 54
  • 100
dvs
  • 511
  • 1
  • 10
  • 27
  • i got the script from the following thread.http://stackoverflow.com/questions/16248513/parse-a-plain-text-file-into-a-csv-file-using-python – dvs Oct 05 '14 at 03:04
  • As an aside, have you considered using Pandas instead of R? – Nick T Oct 05 '14 at 03:35
  • No, actually I am developing an app using R. So I need this file as the input for app – dvs Oct 05 '14 at 04:21

2 Answers2

0

If you want the CSV file to be opened by Excel, then I suggest letting the CSV writer know that through the dialect parameter.

        writer = csv.writer(out_file, dialect=csv.excel)
Miss Yu
  • 41
  • 2
0

if you want the data presented like this, change 3 to 1 , without the blank line ,just edit the "w" with "wb" {cr:CSV file written with Python has blank lines between each row) I sill look for other methods to cut the group words into columns.

enter image description here

Community
  • 1
  • 1
C. Hong
  • 1
  • 2