print df columns code example

Example 1: get column names as list

public static List<String> getColumnNames(){


        List<String> columnList = new ArrayList<>();
        try {
            ResultSetMetaData rsMetaData = rs.getMetaData();
            for (int colNum = 1; colNum < getColumnCount()  ; colNum++) {
                columnList.add(rsMetaData.getColumnLabel(colNum));
            }
        } catch (SQLException e) {
       System.out.println("ERROR WHILE GETTING COLUMN NAMES "+ e.getMessage());
        }

        return columnList;
    }

Example 2: print columns pandas

df = pd.DataFrame(exam_data , index=labels)

# print the columns labeled "name" and "score"
print(df[['name', 'score']])