Forum Discussion
FICO
6 years agoCommunity Manager
Reading CSV files
I'm not quite sure what it is that I'm doing wrong here, but I've been getting "SHEET: Wrong number of columns (req:3 found:2)" whenever I try to load data from a csv/xlsx file.
To elaborate upon the issue, I've been trying to create a new problem based on h3portf.mos and h3portf.dat in the following link by changing variable names and adding more rows to the data:
https://examples.xpress.fico.com/example.pl?id=mosel_app_8_10
I do realize that the example data files are in .dat format, but since I'll be doing optimization problems on a much larger scale than this I created a new data file in Excel.
As the columns are of different lengths I wrote the initializations code in the following manner:
initializations from "mmsheet.csv:"+FILENAME
CAPITAL as "[A2]"
RETURNS as "[A5:A34]"
US_STOCKS as "[B5:B19]"
BANKS as "[C5:C13]"
end-initializations
When I kept getting the aforementioned error message I tried the R*C* method to the same result. Any assistance would be very much appreciated.
2 Replies
- FICOCommunity Manager
When reading data arrays from spreadsheet the default setting assumes that the selected input range contains the required index values: this is not the case in your example. You therefore need to work with the 'noindex' option:
RETURNS as "noindex;[A5:A34]"
This obviously means that the index range needs to have been stated in the model before you read in the data. For a more flexible setup it would probably be better to remove this definition from the data and add an index column to your spreadsheet file, so the model should just have the declaration
SHARES: range
and you either add an additional first column with index values for the array to your spredsheet, or you can work with the option 'autondx' to generate the indices automatically:
RETURNS as "autondx;[A5:A34]"
(Note that the other data items are either scalar values or sets, so the remark about indices does not apply to them.)
One further suggestion: to make the data input more flexible you could also reorganize the format of your spreadsheet so that each column corresponds a one data item, where the first row contains the headers, then data values in the rest of the respective column, in which case you can simply read the entire columns (using the option 'skiph' to ignore the header line), for example:
initializations from 'mmsheet.csv:skiph;h3portf2.csv' RETURNS as "autondx;[A:A]" ! Header in A1, data values starting in A2 CAPITAL as "[E:E]" ! Assuming that this value is now in field E2 US_STOCKS as "[B:B]" BANKS as "[C:C]" end-initializations - FICOCommunity Manager
Thank you so much @Susanne Heipcke, your answer was just the thing I needed!
Related Content
Related Content
Reading problem from .lp file into Julia
I'm reading a problem from .lp into Julia. I've tried various xpress.optimizer params - the problem is infeasible. The reason is b/c the model isn't read exactly as it's defined in the .lp file - som...4 years agoPlace FICO® Xpress Optimization ForumFICO® Xpress Optimization Forum8 unread comments8 unread14Views0likes8CommentsProblem with reading from an Excel file
I tried to read data from an Excel file into Xpress IVE. However, I get the following error message: "Mosel: E-22: I cannot open file `mmsheet.excel:data.xlsx' for reading (Invalid class string )." ...4 years agoPlace FICO® Xpress Optimization ForumFICO® Xpress Optimization Forum2 unread comments2 unread4Views0likes2CommentsCan the CSV file generated by "Export Decision Table" default to Unicode instead of ASCII?
When I am looking at a Decision Table in Fico Blaze Advisor, I am able to click a button for "Export Decision Table" to create a CSV file with the data in the table. When the CSV file is created, it ...10Views0likes3Comments