Array dump_csv Method
Syntax
Arguments
- hasFieldNames Logical
If .t., Emit field names for the first row.
- restrictColumnsCharacter
Comma separated list of field names to emit, allowing column ordering and filtering of which columns are used.
Returns
- resultCharacter
Returns the property array as formatted csv.
Description
Returns the property array as formatted csv. Optionally define the fields to include and whether or not field names should be included in the csv output in the first line of data.
Example
Consider the following array arr, which contains the following fields and data:
? arr.get_fields() = ticker name price change mktcap chgPct ? arr.dump_properties("ticker|name|price|change|mktcap|chgPct") = AAPL|Apple Inc.|402.215|-24.025|377.7B|-24.025 - -5.64% GOOG|Google Inc.|780.37|-13|257.3B|-13.00 - -1.64% MSFT|Microsoft Corpora|28.8349|-0.1351|241.5B|-0.1351 - -0.47% INTC|Intel Corporation|22.067|0.152|109.1B|+0.152 - +0.69% HPQ|Hewlett-Packard C|20.48|-0.55|39.814B|-0.55 - -2.62% ORCL|Oracle Corporatio|32.528|-0.887|153.2B|-0.887 - -2.65% CSCO|Cisco Systems, In|20.625|-0.535|110.0B|-0.535 - -2.53% DELL|Dell Inc.|14.005|-0.035|24.470B|-0.035 - -0.25% YHOO|Yahoo! Inc.|23.696|-0.094|26.096B|-0.094 - -0.40% FB|Facebook, Inc.|26.5912|-0.3288|63.344B|-0.3288 - -1.22% LNKD|LinkedIn Corporat|180.29|-2.18|19.661B|-2.18 - -1.19% GRPN|Groupon, Inc.|6.37|-0.01|4.194B|-0.01 - -0.16% YELP|Yelp Inc. Class A|25.545|-0.165|1.628B|-0.165 - -0.64%
arr can be converted to a csv format using the <array>.dump_csv() method as shown below:
? arr.dump_csv() = "AAPL","Apple Inc.",402.215,-24.025,"377.7B","-24.025 - -5.64%" "GOOG","Google Inc.",780.37,-13,"257.3B","-13.00 - -1.64%" "MSFT","Microsoft Corpora",28.8349,-0.1351,"241.5B","-0.1351 - -0.47%" "INTC","Intel Corporation",22.067,0.152,"109.1B","+0.152 - +0.69%" "HPQ","Hewlett-Packard C",20.48,-0.55,"39.814B","-0.55 - -2.62%" "ORCL","Oracle Corporatio",32.528,-0.887,"153.2B","-0.887 - -2.65%" "CSCO","Cisco Systems, In",20.625,-0.535,"110.0B","-0.535 - -2.53%" "DELL","Dell Inc.",14.005,-0.035,"24.470B","-0.035 - -0.25%" "YHOO","Yahoo! Inc.",23.696,-0.094,"26.096B","-0.094 - -0.40%" "FB","Facebook, Inc.",26.5912,-0.3288,"63.344B","-0.3288 - -1.22%" "LNKD","LinkedIn Corporat",180.29,-2.18,"19.661B","-2.18 - -1.19%" "GRPN","Groupon, Inc.",6.37,-0.01,"4.194B","-0.01 - -0.16%" "YELP","Yelp Inc. Class A",25.545,-0.165,"1.628B","-0.165 - -0.64%"
If we wanted to include the field names in the csv output, we can pass .t. as the first parameter to the <array>.dump_csv() method. This will print the properties as a comma-delimited string in the first row of the csv output:
? arr.dump_csv(.t.) = "ticker","name","price","change","mktcap","chgPct" "AAPL","Apple Inc.",402.215,-24.025,"377.7B","-24.025 - -5.64%" "GOOG","Google Inc.",780.37,-13,"257.3B","-13.00 - -1.64%" "MSFT","Microsoft Corpora",28.8349,-0.1351,"241.5B","-0.1351 - -0.47%" "INTC","Intel Corporation",22.067,0.152,"109.1B","+0.152 - +0.69%" "HPQ","Hewlett-Packard C",20.48,-0.55,"39.814B","-0.55 - -2.62%" "ORCL","Oracle Corporatio",32.528,-0.887,"153.2B","-0.887 - -2.65%" "CSCO","Cisco Systems, In",20.625,-0.535,"110.0B","-0.535 - -2.53%" "DELL","Dell Inc.",14.005,-0.035,"24.470B","-0.035 - -0.25%" "YHOO","Yahoo! Inc.",23.696,-0.094,"26.096B","-0.094 - -0.40%" "FB","Facebook, Inc.",26.5912,-0.3288,"63.344B","-0.3288 - -1.22%" "LNKD","LinkedIn Corporat",180.29,-2.18,"19.661B","-2.18 - -1.19%" "GRPN","Groupon, Inc.",6.37,-0.01,"4.194B","-0.01 - -0.16%" "YELP","Yelp Inc. Class A",25.545,-0.165,"1.628B","-0.165 - -0.64%"
If we only wanted to generate csv for the name, ticker, and price properties, we can explicitly output these fields as shown below:
? arr.dump_csv(.f.,"name,ticker,price") = "Apple Inc.","AAPL",402.215 "Google Inc.","GOOG",780.37 "Microsoft Corpora","MSFT",28.8349 "Intel Corporation","INTC",22.067 "Hewlett-Packard C","HPQ",20.48 "Oracle Corporatio","ORCL",32.528 "Cisco Systems, In","CSCO",20.625 "Dell Inc.","DELL",14.005 "Yahoo! Inc.","YHOO",23.696 "Facebook, Inc.","FB",26.5912 "LinkedIn Corporat","LNKD",180.29 "Groupon, Inc.","GRPN",6.37 "Yelp Inc. Class A","YELP",25.545
See Also