public static DataFrame toDataFrame()

in freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/dataframe/impl/CSVConverter.java [35:66]


    public static DataFrame toDataFrame(CSVParser csvParser) {
        try {
            final List<String> headerNames = csvParser.getHeaderNames();
            final DataFrameBuilder builder = DataFrameBuilder.create();
            final List<CSVRecord> records = csvParser.getRecords();
            final CSVRecord firstRecord = records.get(0);

            //  build dataframe with headers
            if (!headerNames.isEmpty()) {
                headerNames.forEach(builder::addStringColumn);
            } else {
                for (int i = 0; i < firstRecord.size(); i++) {
                    builder.addStringColumn(ConverterUtils.getAlphaColumnName(i + 1));
                }
            }

            final DataFrame dataFrame = builder.build();

            // populate rows
            final String[] currValues = new String[firstRecord.size()];
            for (CSVRecord csvRecord : records) {
                for (int i = 0; i < currValues.length; i++) {
                    currValues[i] = csvRecord.get(i);
                }
                dataFrame.append(currValues);
            }

            return dataFrame;
        } catch (IOException e) {
            throw new RuntimeException("Unable to create DataFrame", e);
        }
    }