Python with mysql | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Python with mysql

When we use fetchall in MySQL with python it returns data in tuple form but if o want that data in tabular form . What should I do ?

30th Jul 2022, 12:18 PM
Om Yele
Om Yele - avatar
15 Answers
+ 2
What is tabular form? That's not a data type in python
30th Jul 2022, 12:21 PM
Slick
Slick - avatar
+ 2
Hi, Om Yele ! Have you checked out Pandas. It’s a Python package that are suitable to realational or labeled data. To me, it remindes me to what you mentions as ”tabular form”.
30th Jul 2022, 1:26 PM
Per Bratthammar
Per Bratthammar - avatar
+ 1
No see in can I do it with dataframe to display all the data in tabular form
30th Jul 2022, 12:31 PM
Om Yele
Om Yele - avatar
+ 1
Thankyou
30th Jul 2022, 3:31 PM
Om Yele
Om Yele - avatar
0
No not like that . See I am working on a project in which there is a python which includes python and MySQL code . I had inserted my records. When I want to display it . I display it with fetchall but it returns a list in tuple
30th Jul 2022, 12:23 PM
Om Yele
Om Yele - avatar
0
I want to convert that list to tabular form
30th Jul 2022, 12:24 PM
Om Yele
Om Yele - avatar
0
Okay..? So it comes back in a tuple. Do what you want with it after that then. You'll have to code something to display it
30th Jul 2022, 12:25 PM
Slick
Slick - avatar
0
That's what I am asking see eg . Looks like this [(1, Ash, usa) ( 2 , Naruto, Japan) ]. So I want to display it in a tabular form. So it will look presentable
30th Jul 2022, 12:28 PM
Om Yele
Om Yele - avatar
0
I am working on a project for a client
30th Jul 2022, 12:28 PM
Om Yele
Om Yele - avatar
0
And? What have you tried? Just access each tuple inside the list and print the contents. What. Is. Tabular?
30th Jul 2022, 12:29 PM
Slick
Slick - avatar
0
Then do it
30th Jul 2022, 12:37 PM
Slick
Slick - avatar
0
if u want to print as a tabular form then use JSON notation to print the data of ur selected query. It is a very good approach in printing data to the console....r else where ever you want...!
30th Jul 2022, 4:18 PM
Vamsi G
Vamsi G - avatar
0
Or use NumPy
31st Jul 2022, 12:15 PM
DasKaenguru
0
np.asarray(tuple) returns an array with matrix format when printed
31st Jul 2022, 12:18 PM
DasKaenguru
0
Thankyou
31st Jul 2022, 12:26 PM
Om Yele
Om Yele - avatar