-2

I have an image which is the extracted row of a table and it looks like this: enter image description here

I want to extract each column which is separated by vertical lines into a list.

The expected output will be like this:

['Sl No','Description of Goods','HSN/SAC','Quantity','Rate','per','Amount']

The image is not from a DB, It is just an image that is extracted by some ML model.

How can I achieve this?

ReaL_HyDRA
  • 314
  • 1
  • 18

2 Answers2

-1

As information provided by you, it seems the output you are expecting is table's column names.

Generally cursor instance gives this metadata nicely out of the box.

Here is the pseudocode which will give you the expected output (As of right now no database is mentioned in the question):

# your database package/driver initialization

cursor = conn.cursor()
cursor.execute("your select query")
columns = [column[0] for column in cursor.description]

Variable columns will hold your necessary output.

More read about cursor and description right from documentation: https://docs.python.org/3/library/sqlite3.html#sqlite3.Cursor.description

https://peps.python.org/pep-0249/#description

Hope this helps, Thanks.

cherry
  • 24
  • 4
-1

I think, that you want to obtain columns' content, right ? So, you can make this...

db = sqlite3.connect('database.db') #I don't know which technology you use, just for example...
cursor = db.cursor()
cursor.execute('SELECT * FROM database')
data = cursor.fetchall()
columns = [list(map(lambda x: x[i], data)) for i in range(len(data[0]))]

columns is a list of columns, wich are lists of values. The values in the database.