Siva Sai
Siva Sai

Reputation: 396

python code for print data in csv

import csv

reader = csv.reader(post.text, quotechar="'")

with open('source91.csv', 'wb') as f:

  writer = csv.writer(f)
  writer.writerows(list(reader))

output is showing vertically i need to print the data horizantally in CSV

Upvotes: 1

Views: 123

Answers (1)

sriramkumar
sriramkumar

Reputation: 164

Simple Answer : if you have only one array

with open('source91.csv', 'wb') as f:
    writer = csv.writer(f, delimiter='\n')
    writer.writerows(list(reader))

Complicated answer:

you may need numpy to make is happen. transpose will simply converts row to column

import numpy as np
a = np.array(list(reader))
a = np.append(a, list(reader)) # if you have multiple lines 
a = np.transpose(a)
np.savetxt('source91.csv', a)

Upvotes: 1

Related Questions