2 Replies - 352 Views - Last Post: 06 June 2015 - 11:21 AM Rate Topic: -----

#1 Ripery  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 13-October 14

How to export data into Excel

Posted 04 June 2015 - 10:29 AM

Hello guys . Can someone help me out with this Python code . I want to export the x[i][k] values into excel with matrix form. For example x11=0 , x12=1, x13=0 x14=0
x21=0 , x22=0, x23=1 x24=0
And so on (I have attached my matrix figure)
def _build_problem(self):
        '''
        builds the problem from provided data,
        i.e. adds constraints, defines obj func. etc.
        '''
        if self.modelBuild:
            return
        self.modelBuild = True
        x = {}
        for i in self.taskList:
            x[i] = {}
            for k in self.workstationList:
                x[i][k] = LpVariable('x_'+i+','+k, 0, 1, LpBinary)
        t = LpVariable('T', None, None, LpContinuous)
        # add obj function 
        self.__iadd__(t)
        #add task assignment constraint
        for i in self.taskList:
            taskAssignment = lpSum(x[i][k] for k in self.workstationList)
            self.__iadd__(taskAssignment==1)
        #add cycle time constraints
        for k in self.workstationList:
            cycleTimeC = lpSum(self.taskTime[i]*x[i][k] for i in self.taskList)
            self.__iadd__(t>=cycleTimeC)
        #add precedence constraints
        for i in self.taskList:
            if i in self.pred:
                for h in self.pred[i]:
                    for k in self.workstationList:
                        precedenceC = lpSum(x[h][str(j)] for j in range(1,int(k)+1))
                        precedenceC = precedenceC - x[i][k] 
                        self.__iadd__(precedenceC>=0)


Is This A Good Question/Topic? 0
  • +

Replies To: How to export data into Excel

#2 DblAAssassin  Icon User is offline

  • D.I.C Regular

Reputation: 38
  • View blog
  • Posts: 283
  • Joined: 11-May 13

Re: How to export data into Excel

Posted 06 June 2015 - 11:07 AM

I was doing some reading on the topic, and people were suggesting to export to a .csv file. Others recommend to export to a DataFrame. There are also many modules that can help... https://github.com/python-excel.

Hope I was a help.

I wasn't sure if you needed help with the code or help with how to do it. If you could clarify that would be great.
Was This Post Helpful? 1
  • +
  • -

#3 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 8641
  • View blog
  • Posts: 14,909
  • Joined: 19-March 11

Re: How to export data into Excel

Posted 06 June 2015 - 11:21 AM

If you just need the data, it's almost always easier to just spit out a csv.
Check the documentation for the csv module for details, it's pretty straightforward to use.

If you want to modify a full-bore excel document, with embedded functions and such - well, excel is a notoriously befuckled mess, and its maintainers are not known for their commitment to openness, or for their attention to preserving stability over time, or for their attention to backwards compatibility, so it's probably a lot more trouble than it's worth. Libraries for dealing with excel tend to be errorful and out of date. Good luck!
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1