0

My table data has 5 columns and 5288 rows. I am trying to read that data into a CSV file adding column names. The code for that looks like this :

cursor = conn.cursor()
cursor.execute('Select * FROM classic.dbo.sample3')

rows = cursor.fetchall()

print ("The data has been fetched")

dataframe = pd.DataFrame(rows, columns =['s_name', 't_tid','b_id', 'name', 'summary'])
dataframe.to_csv('data.csv', index = None)

The data looks like this

s_sname   t_tid   b_id  name   summary
---------------------------------------------------------------------------
db1       001     100   careie  hello this is john speaking blah blah blah

It looks like above but has 5288 such rows.

When I try to execute my code mentioned above it throws an error saying :

ValueError: Shape of passed values is (5288, 1), indices imply (5288, 5)

I do not understand what wrong I am doing.

1 Answer 1

1

Use this.

dataframe = pd.read_sql('Select * FROM classic.dbo.sample3',con=conn)
dataframe.to_csv('data.csv', index = None)
Sign up to request clarification or add additional context in comments.

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.