1

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

1
  • getiing output in csv but printing vertically.... Commented Nov 22, 2016 at 6:36

1 Answer 1

1

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

3 Comments

after executing above code the file is saved in NPY file...but i want to save it as CSV
i am having lots of data in post.text variable
savetxt(fname, X, fmt, delimiter, newline, header, footer, comments) savetxt support only these getting error TypeError: Mismatch between array dtype ('object') and format specifier ('%.18e')

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.