Python Forum
Best way to get data from 2D array
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Best way to get data from 2D array
#21
Main.py:
from Team_data import team_data_function
from Comparison import comparison_function
from Team_calc import team_calc_function

team_data_function()

comparison_function()
team_calc_function()
Team_data.py:
class Teams:


import os
import string


class Teams:

    def __init__(self, legaue ="", name = "", strength = 0, form = 0, injuries = 0, motivation = 0, city="", date="" ):
Team_calc.py_
import os
import string
from Team_data import team_data_function
from Team_data import Teams

def team_calc_function():

   print(dict_teams["Fulham"].name)
Reply
#22
It looks like you're not defining dict_teams anywhere. You should be creating it somewhere Team_calc.py has access to and passing it to team_calc_function as a parameter.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#23
Yeah that worked, Thank you! :)
Reply
#24
Hi, i changed the model from reading csv-file to reading xlsx-file with xlrd and encounterd some weird problems.

here's the code:

    xl_fil_resultat = xlrd.open_workbook("Data/resultat.xlsx")
    sheet_resultat = xl_fil_resultat.sheet_by_index(0)
    resultat.append(sheet_resultat.row_values(0)) # First row is text that cant use datemode
    
    for i in range(1, sheet_resultat.nrows):
        resultat.append(sheet_resultat.row_values(i))
        date_cell = sheet_resultat.cell(i,1).value
        resultat[i][1]= xlrd.xldate_as_tuple(date_cell, xl_fil_resultat.datemode)
        print(resultat[i])
here is the result:

['E0', (2019, 2, 9, 0, 0, 0), 'Watford', 'Everton', 1.0, 0.0, 'H', 0.0, 0.0, 'D', 'L Probert']
['E0', (2019, 2, 10, 0, 0, 0), 'Man City', 'Chelsea', 6.0, 0.0, 'H', 4.0, 0.0, 'H', 'M Dean']
['E0', (2019, 2, 10, 0, 0, 0), 'Tottenham', 'Leicester', 3.0, 1.0, 'H', 1.0, 0.0, 'H', 'M Oliver']
['E0', (2019, 2, 11, 0, 0, 0), 'Wolves', 'Newcastle', 1.0, 1.0, 'D', 0.0, 0.0, 'D', 'G Scott']

Everything looks fine here. The problem is that i have several sheets and when i try to iterate over them using a for loop everything gets messy.

    for n in range(5):
        sheet_resultat = xl_fil_resultat.sheet_by_index(n)
        resultat.append(sheet_resultat.row_values(0)) # First row is text that cant use datemode

        for i in range(1, sheet_resultat.nrows):
            resultat.append(sheet_resultat.row_values(i))
            date_cell = sheet_resultat.cell(i,1).value
            resultat[i][1]= xlrd.xldate_as_tuple(date_cell, xl_fil_resultat.datemode)
            print(resultat[i])
['E0', (2019, 2, 9, 0, 0, 0), 'Liverpool', 'Newcastle', 4.0, 0.0, 'H', 1.0, 0.0, 'H', 'G Scott']
['E0', (2019, 2, 9, 0, 0, 0), 'Man United', 'Huddersfield', 3.0, 1.0, 'H', 1.0, 0.0, 'H', 'J Moss']
['E0', (2019, 2, 10, 0, 0, 0), 'Tottenham', 'Bournemouth', 5.0, 0.0, 'H', 3.0, 0.0, 'H', 'C Kavanagh']
['E0', (2019, 2, 10, 0, 0, 0), 'Watford', 'Chelsea', 1.0, 2.0, 'A', 1.0, 1.0, 'D', 'M Atkinson']

First of all, it doesn't iterate over different sheets. Second, it suddenly mixes the items in the list so suddenly Tottenham is playing home against Bournemouth... (I cut out the last 4 matches of a longer list, therefore the teams are different because of the mixes)

If i manually changes to sheet 1,2,3,4,5... it works just fine. I'm really confused here, hoping for some good advices :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Seeing al the data in a dataframe or numpy.array Led_Zeppelin 1 1,145 Jul-11-2022, 08:54 PM
Last Post: Larz60+
Question Change elements of array based on position of input data Cola_Reb 6 2,137 May-13-2022, 12:57 PM
Last Post: Cola_Reb
  how to print all data from all data array? korenron 3 2,477 Dec-30-2020, 01:54 PM
Last Post: korenron
  Import CSV data into array and turn into integers DoctorSmiles 5 3,208 Jul-16-2020, 10:47 AM
Last Post: perfringo
  Issue with creating an array of pixel data for PNG files in Google Colab The_Sarco 1 1,931 Apr-29-2020, 12:03 AM
Last Post: bowlofred
  python3 List to array or string to extract data batchenr 4 3,265 May-28-2019, 01:44 PM
Last Post: buran
  Reading data from serial port as byte array vlad93 1 12,082 May-18-2019, 05:26 AM
Last Post: heiner55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020