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.

3
  • i got the script from the following thread.stackoverflow.com/questions/16248513/… Commented Oct 5, 2014 at 3:04
  • As an aside, have you considered using Pandas instead of R? Commented Oct 5, 2014 at 3:35
  • No, actually I am developing an app using R. So I need this file as the input for app Commented Oct 5, 2014 at 4:21

2 Answers 2

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)
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.