Getting the column name of DataFrame is a simple operation with the following methods:
Column for column in df]
2. Df.columns. Values return array
3. List (df)
4. Df.columns return Index (tolist(), or list(array)
import pandas as pd
from numpy.random import randint
df = pd.DataFrame(columns=list('abcdefghij'))
%timeit [column for column in df]
%timeit list(df.columns.values)
%timeit list(df)
%timeit list(df.columns)
# 100000 loops, best of 3: 2.24 µs per loop
%timeit df.columns.tolist()
# 1000000 loops, best of 3: 1.77 µs per loop
Read More:
- Pandas multi column pandas.core.indexing . indexingerror: too many indexers error
- Pandas sort according to a column_ values)
- Error attempting to get column ‘STAFF_NAME’ from result set
- Error attempting to get column from result set
- Error attempting to get column ‘failure_msg‘ from result set
- Error attempting to get column time from result set. Cause: java.sql.SQLFe
- Error attempting to get column ‘xxxxx’ from result set — after Lombok is annotated with builder, mybatis cannot recognize the correct type of field
- Word column after the text evenly distributed in the left and right two columns, rather than fill in the left column and then fill in the right column, how to do?
- Pandas generates new columns through LOC
- Reintex index of pandas
- Methods of modifying index and columns names by dataframe in pandas
- In the SQL query statement, add the column that does not exist in the table and set the fixed value of the column
- Summary of three methods for pandas to convert dict into dataframe
- Three methods of converting dict into dataframe by pandas
- Converting string object into datetime type in pandas
- In pandas, dataframe and np.array The mutual transformation between the two
- Problem solving: Pandas: keyerror: [ ] not in index
- [Python] pandas Library pd.to_ Parameter arrangement and example of Excel operation writing into excel file
- Pandas memory error
- On set in pandas_ Index and reset_ Usage of index