df get column names code example

Example 1: python return column names of pandas dataframe

# Basic syntax:
your_dataframe.columns

# Note, if you want the column names as a list, just do:
list(your_dataframe.columns)

Example 2: pd dataframe get column names

lst = data.columns.values     # data is dataframe

Example 3: python select columns names from dataframe

# Import pandas package  
import pandas as pd  
    
# making data frame  
data = pd.read_csv("nba.csv")  
  
# iterating the columns 
for col in data.columns: 
    print(col)

Example 4: pandas dataframe column names

print(data.columns.values)

Example 5: dataframe names pandas

print(df.rename(columns={'A': 'a', 'C': 'c'}))

Example 6: get column names

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;
    }

Tags:

Misc Example