Python - creating table

Asked

Viewed 1,038 times

0

I have two variables (coordinates X,Y) that I am taking this information from a table . plt, I would like to save them in another table. I’d like the table to look like this

   X   Y
  10   48
  10   50
  20   30 

I am new in python, could you access this table for reading after indicating the variable ( X or Y ) and the line to view this variable? this table would have to have a variable size because the size of it will depend on the file I will load

2 answers

0

You can use a python tuple to do this.

##Primeira X, segunda Y
tabela = [ (10,48 ), ( 10,50 ), (20, 30 ) ]

tabela[0] would return (10,48) If you want to access X, you only need to access the first item: tabela[0][0]

There is also a way for you to create the table so that each element

>>> tabela = [ (10,48 ), ( 10,50 ), (20, 30 ) ]
>>> tabela[0][0]
10
  • thanks for your reply, but I can save these variables anywhere in the table ?

  • Sorry, I didn’t understand your question. You say export the information?

0

Tables can be represented using different types of Data Structure. The simplest would be to create an array using arrays:

table = [ [10,48] , [10,50] , [20,30] ]

You can access the data using the index as:

''' Acessar cada linha '''
>>> table[0]
[10,48]
''' Ou acessar diretamento o valor por coluna: '''
>>> table[0][1]
48

But if you want to store this data externally, it would be interesting to use the Pandas to convert to CSV, Excel, etc.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.