Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Đọc
Python3
Bàn luận
Mặc dù phân tích các bộ dữ liệu thực thường có kích thước rất lớn, chúng ta có thể cần phải lấy tên cột để thực hiện một số hoạt động nhất định. Hãy để thảo luận về cách lấy tên cột trong Pandas DataFrame. Đầu tiên, hãy để Lôi tạo một khung dữ liệu đơn giản với tệp NBA.CSV. & NBSP; Simply iterating over columns
Python3
Bây giờ, hãy để cố gắng lấy tên các cột từ trên tập dữ liệu.
Phương pháp số 1: Chỉ cần lặp lại trên các cột & nbsp;
['product_name',
'Unit_Price',
'No_Of_Units',
'Available_Quantity',
'Available_Since_Date']
3 ['product_name',
'Unit_Price',
'No_Of_Units',
'Available_Quantity',
'Available_Since_Date']
4import pandas as pd
data = {"product_name":["Keyboard","Mouse", "Monitor", "CPU", "Speakers",pd.NaT],
"Unit_Price":[500,200, 5000, 10000, 250.50,350],
"No_Of_Units":[5,5, 10, 20, 8,pd.NaT],
"Available_Quantity":[5,6,10,"Not Available", pd.NaT,pd.NaT],
"Available_Since_Date":['11/5/2021', '4/23/2021', '08/21/2021','09/18/2021','01/05/2021',pd.NaT]
}
df = pd.DataFrame[data]
# Converting one column as float to demonstrate dtypes
df = df.astype[{"Unit_Price": float}]
df
4import pandas as pd
data = {"product_name":["Keyboard","Mouse", "Monitor", "CPU", "Speakers",pd.NaT],
"Unit_Price":[500,200, 5000, 10000, 250.50,350],
"No_Of_Units":[5,5, 10, 20, 8,pd.NaT],
"Available_Quantity":[5,6,10,"Not Available", pd.NaT,pd.NaT],
"Available_Since_Date":['11/5/2021', '4/23/2021', '08/21/2021','09/18/2021','01/05/2021',pd.NaT]
}
df = pd.DataFrame[data]
# Converting one column as float to demonstrate dtypes
df = df.astype[{"Unit_Price": float}]
df
5import pandas as pd
data = {"product_name":["Keyboard","Mouse", "Monitor", "CPU", "Speakers",pd.NaT],
"Unit_Price":[500,200, 5000, 10000, 250.50,350],
"No_Of_Units":[5,5, 10, 20, 8,pd.NaT],
"Available_Quantity":[5,6,10,"Not Available", pd.NaT,pd.NaT],
"Available_Since_Date":['11/5/2021', '4/23/2021', '08/21/2021','09/18/2021','01/05/2021',pd.NaT]
}
df = pd.DataFrame[data]
# Converting one column as float to demonstrate dtypes
df = df.astype[{"Unit_Price": float}]
df
6Output:
['product_name',
'Unit_Price',
'No_Of_Units',
'Available_Quantity',
'Available_Since_Date']
5 ['product_name',
'Unit_Price',
'No_Of_Units',
'Available_Quantity',
'Available_Since_Date']
6 ['product_name',
'Unit_Price',
'No_Of_Units',
'Available_Quantity',
'Available_Since_Date']
7 ['product_name',
'Unit_Price',
'No_Of_Units',
'Available_Quantity',
'Available_Since_Date']
8 ['product_name',
'Unit_Price',
'No_Of_Units',
'Available_Quantity',
'Available_Since_Date']
9import pandas as pd
data = {"product_name":["Keyboard","Mouse", "Monitor", "CPU", "Speakers",pd.NaT],
"Unit_Price":[500,200, 5000, 10000, 250.50,350],
"No_Of_Units":[5,5, 10, 20, 8,pd.NaT],
"Available_Quantity":[5,6,10,"Not Available", pd.NaT,pd.NaT],
"Available_Since_Date":['11/5/2021', '4/23/2021', '08/21/2021','09/18/2021','01/05/2021',pd.NaT]
}
df = pd.DataFrame[data]
# Converting one column as float to demonstrate dtypes
df = df.astype[{"Unit_Price": float}]
df
0 import pandas as pd
data = {"product_name":["Keyboard","Mouse", "Monitor", "CPU", "Speakers",pd.NaT],
"Unit_Price":[500,200, 5000, 10000, 250.50,350],
"No_Of_Units":[5,5, 10, 20, 8,pd.NaT],
"Available_Quantity":[5,6,10,"Not Available", pd.NaT,pd.NaT],
"Available_Since_Date":['11/5/2021', '4/23/2021', '08/21/2021','09/18/2021','01/05/2021',pd.NaT]
}
df = pd.DataFrame[data]
# Converting one column as float to demonstrate dtypes
df = df.astype[{"Unit_Price": float}]
df
1import pandas as pd
data = {"product_name":["Keyboard","Mouse", "Monitor", "CPU", "Speakers",pd.NaT],
"Unit_Price":[500,200, 5000, 10000, 250.50,350],
"No_Of_Units":[5,5, 10, 20, 8,pd.NaT],
"Available_Quantity":[5,6,10,"Not Available", pd.NaT,pd.NaT],
"Available_Since_Date":['11/5/2021', '4/23/2021', '08/21/2021','09/18/2021','01/05/2021',pd.NaT]
}
df = pd.DataFrame[data]
# Converting one column as float to demonstrate dtypes
df = df.astype[{"Unit_Price": float}]
df
2 import pandas as pd
data = {"product_name":["Keyboard","Mouse", "Monitor", "CPU", "Speakers",pd.NaT],
"Unit_Price":[500,200, 5000, 10000, 250.50,350],
"No_Of_Units":[5,5, 10, 20, 8,pd.NaT],
"Available_Quantity":[5,6,10,"Not Available", pd.NaT,pd.NaT],
"Available_Since_Date":['11/5/2021', '4/23/2021', '08/21/2021','09/18/2021','01/05/2021',pd.NaT]
}
df = pd.DataFrame[data]
# Converting one column as float to demonstrate dtypes
df = df.astype[{"Unit_Price": float}]
df
3Method #2: Using columns attribute with dataframe object Python3
Bây giờ, hãy để cố gắng lấy tên các cột từ trên tập dữ liệu.
Phương pháp số 1: Chỉ cần lặp lại trên các cột & nbsp;
df.columns
4df.columns
5Output:
['product_name',
'Unit_Price',
'No_Of_Units',
'Available_Quantity',
'Available_Since_Date']
3 ['product_name',
'Unit_Price',
'No_Of_Units',
'Available_Quantity',
'Available_Since_Date']
4
5 ['product_name',
'Unit_Price',
'No_Of_Units',
'Available_Quantity',
'Available_Since_Date']
6 ['product_name',
'Unit_Price',
'No_Of_Units',
'Available_Quantity',
'Available_Since_Date']
7 ['product_name',
'Unit_Price',
'No_Of_Units',
'Available_Quantity',
'Available_Since_Date']
8 ['product_name',
'Unit_Price',
'No_Of_Units',
'Available_Quantity',
'Available_Since_Date']
9 Using keys[] function: It will also give the columns of the dataframe. ['product_name',
'Unit_Price',
'No_Of_Units',
'Available_Quantity',
'Available_Since_Date']
Python3
Output:
0 import pandas as pd
data = {"product_name":["Keyboard","Mouse", "Monitor", "CPU", "Speakers",pd.NaT],
"Unit_Price":[500,200, 5000, 10000, 250.50,350],
"No_Of_Units":[5,5, 10, 20, 8,pd.NaT],
"Available_Quantity":[5,6,10,"Not Available", pd.NaT,pd.NaT],
"Available_Since_Date":['11/5/2021', '4/23/2021', '08/21/2021','09/18/2021','01/05/2021',pd.NaT]
}
df = pd.DataFrame[data]
# Converting one column as float to demonstrate dtypes
df = df.astype[{"Unit_Price": float}]
df
1import pandas as pd
data = {"product_name":["Keyboard","Mouse", "Monitor", "CPU", "Speakers",pd.NaT],
"Unit_Price":[500,200, 5000, 10000, 250.50,350],
"No_Of_Units":[5,5, 10, 20, 8,pd.NaT],
"Available_Quantity":[5,6,10,"Not Available", pd.NaT,pd.NaT],
"Available_Since_Date":['11/5/2021', '4/23/2021', '08/21/2021','09/18/2021','01/05/2021',pd.NaT]
}
df = pd.DataFrame[data]
# Converting one column as float to demonstrate dtypes
df = df.astype[{"Unit_Price": float}]
df
2 import pandas as pd
data = {"product_name":["Keyboard","Mouse", "Monitor", "CPU", "Speakers",pd.NaT],
"Unit_Price":[500,200, 5000, 10000, 250.50,350],
"No_Of_Units":[5,5, 10, 20, 8,pd.NaT],
"Available_Quantity":[5,6,10,"Not Available", pd.NaT,pd.NaT],
"Available_Since_Date":['11/5/2021', '4/23/2021', '08/21/2021','09/18/2021','01/05/2021',pd.NaT]
}
df = pd.DataFrame[data]
# Converting one column as float to demonstrate dtypes
df = df.astype[{"Unit_Price": float}]
df
3 column.values method returns an array of index. import pandas as pd
data = {"product_name":["Keyboard","Mouse", "Monitor", "CPU", "Speakers",pd.NaT],
"Unit_Price":[500,200, 5000, 10000, 250.50,350],
"No_Of_Units":[5,5, 10, 20, 8,pd.NaT],
"Available_Quantity":[5,6,10,"Not Available", pd.NaT,pd.NaT],
"Available_Since_Date":['11/5/2021', '4/23/2021', '08/21/2021','09/18/2021','01/05/2021',pd.NaT]
}
df = pd.DataFrame[data]
# Converting one column as float to demonstrate dtypes
df = df.astype[{"Unit_Price": float}]
df
Python3
Bây giờ, hãy để cố gắng lấy tên các cột từ trên tập dữ liệu.
Phương pháp số 1: Chỉ cần lặp lại trên các cột & nbsp;
df.columns
4 Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
4Output:
['product_name',
'Unit_Price',
'No_Of_Units',
'Available_Quantity',
'Available_Since_Date']
3 ['product_name',
'Unit_Price',
'No_Of_Units',
'Available_Quantity',
'Available_Since_Date']
4 ['product_name',
'Unit_Price',
'No_Of_Units',
'Available_Quantity',
'Available_Since_Date']
5 ['product_name',
'Unit_Price',
'No_Of_Units',
'Available_Quantity',
'Available_Since_Date']
6 ['product_name',
'Unit_Price',
'No_Of_Units',
'Available_Quantity',
'Available_Since_Date']
7 ['product_name',
'Unit_Price',
'No_Of_Units',
'Available_Quantity',
'Available_Since_Date']
8 ['product_name',
'Unit_Price',
'No_Of_Units',
'Available_Quantity',
'Available_Since_Date']
9Method #5: Using tolist[] method with values with given the list of columns. Python3
Bây giờ, hãy để cố gắng lấy tên các cột từ trên tập dữ liệu.
Phương pháp số 1: Chỉ cần lặp lại trên các cột & nbsp;
df.columns
4df.columns.values
3Output:
['product_name',
'Unit_Price',
'No_Of_Units',
'Available_Quantity',
'Available_Since_Date']
5 ['product_name',
'Unit_Price',
'No_Of_Units',
'Available_Quantity',
'Available_Since_Date']
6 ['product_name',
'Unit_Price',
'No_Of_Units',
'Available_Quantity',
'Available_Since_Date']
7 ['product_name',
'Unit_Price',
'No_Of_Units',
'Available_Quantity',
'Available_Since_Date']
8 ['product_name',
'Unit_Price',
'No_Of_Units',
'Available_Quantity',
'Available_Since_Date']
9import pandas as pd
data = {"product_name":["Keyboard","Mouse", "Monitor", "CPU", "Speakers",pd.NaT],
"Unit_Price":[500,200, 5000, 10000, 250.50,350],
"No_Of_Units":[5,5, 10, 20, 8,pd.NaT],
"Available_Quantity":[5,6,10,"Not Available", pd.NaT,pd.NaT],
"Available_Since_Date":['11/5/2021', '4/23/2021', '08/21/2021','09/18/2021','01/05/2021',pd.NaT]
}
df = pd.DataFrame[data]
# Converting one column as float to demonstrate dtypes
df = df.astype[{"Unit_Price": float}]
df
0 import pandas as pd
data = {"product_name":["Keyboard","Mouse", "Monitor", "CPU", "Speakers",pd.NaT],
"Unit_Price":[500,200, 5000, 10000, 250.50,350],
"No_Of_Units":[5,5, 10, 20, 8,pd.NaT],
"Available_Quantity":[5,6,10,"Not Available", pd.NaT,pd.NaT],
"Available_Since_Date":['11/5/2021', '4/23/2021', '08/21/2021','09/18/2021','01/05/2021',pd.NaT]
}
df = pd.DataFrame[data]
# Converting one column as float to demonstrate dtypes
df = df.astype[{"Unit_Price": float}]
df
1import pandas as pd
data = {"product_name":["Keyboard","Mouse", "Monitor", "CPU", "Speakers",pd.NaT],
"Unit_Price":[500,200, 5000, 10000, 250.50,350],
"No_Of_Units":[5,5, 10, 20, 8,pd.NaT],
"Available_Quantity":[5,6,10,"Not Available", pd.NaT,pd.NaT],
"Available_Since_Date":['11/5/2021', '4/23/2021', '08/21/2021','09/18/2021','01/05/2021',pd.NaT]
}
df = pd.DataFrame[data]
# Converting one column as float to demonstrate dtypes
df = df.astype[{"Unit_Price": float}]
df
2 import pandas as pd
data = {"product_name":["Keyboard","Mouse", "Monitor", "CPU", "Speakers",pd.NaT],
"Unit_Price":[500,200, 5000, 10000, 250.50,350],
"No_Of_Units":[5,5, 10, 20, 8,pd.NaT],
"Available_Quantity":[5,6,10,"Not Available", pd.NaT,pd.NaT],
"Available_Since_Date":['11/5/2021', '4/23/2021', '08/21/2021','09/18/2021','01/05/2021',pd.NaT]
}
df = pd.DataFrame[data]
# Converting one column as float to demonstrate dtypes
df = df.astype[{"Unit_Price": float}]
df
3Method #6: Using sorted[] method : sorted[] method will return the list of columns sorted in alphabetical order. Python3
Bây giờ, hãy để cố gắng lấy tên các cột từ trên tập dữ liệu.
Phương pháp số 1: Chỉ cần lặp lại trên các cột & nbsp;
array[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'], dtype=object]
1 array[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'], dtype=object]
2Output:
Bạn cũng có thể sử dụng cú pháp sau để hiển thị tất cả các tên cột trong DataFrame: Print [DF ..
Làm cách nào để có được các cột cụ thể trong gấu trúc?
Sử dụng dataFrame.loc [] và dataFrame.iloc [] để chọn một cột hoặc nhiều cột từ Pandas DataFrame theo tên/nhãn hoặc vị trí chỉ mục. This is useful when you want to show all columns in a dataframe in the output console [E.g. in the jupyter notebook console].
Làm cách nào để trích xuất một cột từ một bộ dữ liệu trong Python?
Trích xuất Python Python Các cột cụ thể từ Pandas DataFrame Câu trả lời của mã.
# Cú pháp cơ bản:.get column names from pandas dataframe.
Hàm Lambda trả về
14, nếu bất kỳ giá trị nào được sao chép. Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
15, nếu giá trị không được nhân đôi. Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
df.columns
Đoạn trích
Đầu ra
Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
Đây là cách bạn có thể nhận được các tiêu đề cột có chứa các giá trị trùng lặp.get the column headers as a list, use the below snippet.
Tiếp theo, bạn sẽ học cách lấy tên cột theo cách sắp xếp.
Đoạn trích
df.columns.values.tolist[]
Bạn sẽ thấy các tên cột được in dưới dạng danh sách như hình dưới đây.
Đầu ra
['product_name',
'Unit_Price',
'No_Of_Units',
'Available_Quantity',
'Available_Since_Date']
Đây là cách bạn có thể nhận các tiêu đề cột của Pandas DataFrame dưới dạng danh sách.
Nếu bạn muốn hiểu chi tiết, hãy đọc trên
Trong hướng dẫn này, bạn sẽ tìm hiểu các phương pháp khác nhau có sẵn để có được các tiêu đề cột DataFrame của Pandas cho các mục đích khác nhau.different methods available to get the pandas dataframe column headers for various purposes.
- Mẫu dữ liệu
- Gấu trúc nhận được tên cột
- Gấu trúc nhận được danh sách từ các tiêu đề cột DataFrame
- Danh sách gấu trúc tên và các loại
- Gấu trúc nhận được danh sách từ các tiêu đề cột DataFrame dựa trên kiểu dữ liệu
- Gấu trúc nhận được tên cột theo chỉ mục
- Gấu trúc nhận được tên cột đa dạng
- Gấu trúc nhận được tên cột bắt đầu bằng
- Gấu trúc nhận được tên cột dựa trên điều kiện
- Gấu trúc nhận được tên cột với nan
- Gấu trúc nhận được tên cột có giá trị trùng lặp
- Gấu trúc được sắp xếp tên cột
- Sự kết luận
- Bạn cũng có thể thích
Mẫu dữ liệu
Gấu trúc nhận được tên cột
import pandas as pd
data = {"product_name":["Keyboard","Mouse", "Monitor", "CPU", "Speakers",pd.NaT],
"Unit_Price":[500,200, 5000, 10000, 250.50,350],
"No_Of_Units":[5,5, 10, 20, 8,pd.NaT],
"Available_Quantity":[5,6,10,"Not Available", pd.NaT,pd.NaT],
"Available_Since_Date":['11/5/2021', '4/23/2021', '08/21/2021','09/18/2021','01/05/2021',pd.NaT]
}
df = pd.DataFrame[data]
# Converting one column as float to demonstrate dtypes
df = df.astype[{"Unit_Price": float}]
df
Gấu trúc nhận được danh sách từ các tiêu đề cột DataFrame
Danh sách gấu trúc tên và các loại | 500.0 | 5 | 5 | Gấu trúc nhận được danh sách từ các tiêu đề cột DataFrame dựa trên kiểu dữ liệu |
Gấu trúc nhận được tên cột theo chỉ mục | 200.0 | 5 | 6 | Gấu trúc nhận được tên cột đa dạng |
Gấu trúc nhận được tên cột bắt đầu bằng | 5000.0 | 10 | 10 | Gấu trúc nhận được tên cột dựa trên điều kiện |
Gấu trúc nhận được tên cột với nan | 10000.0 | 20 | Gấu trúc nhận được tên cột có giá trị trùng lặp | Gấu trúc được sắp xếp tên cột |
Sự kết luận | 250.5 | 8 | Bạn cũng có thể thích | Đây là khung dữ liệu mẫu được sử dụng trong suốt hướng dẫn. |
Bạn cũng có thể thích | 350.0 | Bạn cũng có thể thích | Bạn cũng có thể thích | Bạn cũng có thể thích |
Đây là khung dữ liệu mẫu được sử dụng trong suốt hướng dẫn.
DataFrame trông giống như get column names using different methods.
Bàn phím
11/5/2021
Đoạn trích
df.columns
Đầu ra
Con chuột23/4/2021
Màn hình
Đoạn trích
df.columns.values
21/08/2021
Đầu ra
array[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'], dtype=object]
CPU
Không có sẵn
Gấu trúc nhận được danh sách từ các tiêu đề cột DataFrame
Danh sách gấu trúc tên và các loạiget column names as list by using the .columns.values property of the dataframe and converting it to a list using the
array[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'], dtype=object]
3 method as shown below.Đoạn trích
df.columns.values.tolist[]
Gấu trúc nhận được danh sách từ các tiêu đề cột DataFrame dựa trên kiểu dữ liệu
Đầu ra
['product_name',
'Unit_Price',
'No_Of_Units',
'Available_Quantity',
'Available_Since_Date']
Gấu trúc nhận được tên cột theo chỉ mục
Gấu trúc nhận được tên cột đa dạng
Đoạn trích
Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
1Gấu trúc nhận được tên cột bắt đầu bằng
Đầu ra
['product_name',
'Unit_Price',
'No_Of_Units',
'Available_Quantity',
'Available_Since_Date']
Gấu trúc nhận được tên cột dựa trên điều kiện
Gấu trúc nhận được tên cột với nan
Danh sách gấu trúc tên và các loại
Gấu trúc nhận được danh sách từ các tiêu đề cột DataFrame dựa trên kiểu dữ liệu
Gấu trúc nhận được tên cột theo chỉ mục
Đoạn trích
Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
3Gấu trúc nhận được tên cột đa dạng
Đầu ra
Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
4Đây là cách bạn có thể nhận các tiêu đề cột của Pandas DataFrame dưới dạng danh sách.
Gấu trúc nhận được danh sách từ các tiêu đề cột DataFrame dựa trên kiểu dữ liệu
Gấu trúc nhận được tên cột theo chỉ mụcget a list from dataframe column headers based on the data type of the column.
Gấu trúc nhận được tên cột đa dạngidentify all the number columns available in the dataframe.
Gấu trúc nhận được tên cột bắt đầu bằng
Gấu trúc nhận được tên cột dựa trên điều kiệnPandas or Numpy.
Đoạn trích
Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
5where,
- Gấu trúc nhận được tên cột với nan
- Gấu trúc nhận được tên cột có giá trị trùng lặp
- Gấu trúc được sắp xếp tên cột
Đầu ra
Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
6Đây là cách bạn có thể nhận các tiêu đề cột của Pandas DataFrame dưới dạng danh sách.
Nếu bạn muốn hiểu chi tiết, hãy đọc trên
Gấu trúc nhận được tên cột theo chỉ mục
Gấu trúc nhận được tên cột đa dạngget column names by using its index.
Gấu trúc nhận được tên cột bắt đầu bằng
Gấu trúc nhận được tên cột dựa trên điều kiệnget the name from a specific index by passing the index to the
array[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'], dtype=object]
9 attribute of the dataframe as shown below.Gấu trúc nhận được tên cột với nan Hence, if you use
df.columns.values.tolist[]
7, you’ll get a column from the third position.
Đoạn trích
Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
7Gấu trúc nhận được tên cột có giá trị trùng lặp
Đầu ra
Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
8Đây là cách bạn có thể nhận được một tiêu đề cột duy nhất bằng chỉ mục.
Tiếp theo, bạn sẽ học bằng cách sử dụng nhiều chỉ số.
Gấu trúc nhận được tên cột đa dạng
Trong phần này, bạn sẽ học cách lấy tên cột bằng cách sử dụng Multi Index.get column names by using the multi index.
Multi Index có thể được sử dụng để nhận nhiều tiêu đề cột từ DataFrame.
Nhiều tiêu đề cột sẽ được in dưới dạng chỉ mục. Chỉ số là một chuỗi bất biến được sử dụng để lập chỉ mục.
Như đã nói trước, chỉ số là 0 dựa trên. Do đó, nếu bạn sử dụng 2, bạn sẽ nhận được một cột từ vị trí thứ ba.
Đoạn trích
Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
9Bạn có thể thấy tiêu đề cột có sẵn ở vị trí
df.columns.values.tolist[]
7 và df.columns.values.tolist[]
8.Đầu ra
df.columns.values.tolist[]
0Đây là cách bạn có thể nhận được nhiều tiêu đề cột bằng chỉ mục.
Tiếp theo, bạn sẽ học cách có được các cột bắt đầu với một
Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
01 cụ thể.Gấu trúc nhận được tên cột bắt đầu bằng
Trong phần này, bạn sẽ học cách lấy tên cột bắt đầu bằng một chữ
Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
01 cụ thể.get column names starting with a specific Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
01 literal.Bạn có thể sử dụng phương thức
Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
03 có sẵn trong đối tượng chuỗi [] trên danh sách tên cột. Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
04 được sử dụng để xác định các cột bằng cách sử dụng tên. Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
05 sẽ mang lại các cột bắt đầu bằng Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
06 và Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
07 sẽ trả về tất cả các cột được trả về bởi Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
03. Sau đó, bạn có thể nhận tên cột bằng thuộc tính array[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'], dtype=object]
9.get the column names using the array[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'], dtype=object]
9 attribute.Đoạn trích
df.columns.values.tolist[]
1Bạn có thể thấy tiêu đề cột có sẵn ở vị trí
df.columns.values.tolist[]
7 và df.columns.values.tolist[]
8.Đầu ra
df.columns.values.tolist[]
2Đây là cách bạn có thể nhận được nhiều tiêu đề cột bằng chỉ mục.
Tiếp theo, bạn sẽ học cách có được các cột bắt đầu với một
Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
01 cụ thể.Gấu trúc nhận được tên cột bắt đầu bằng
Trong phần này, bạn sẽ học cách lấy tên cột bắt đầu bằng một chữ
Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
01 cụ thể.get column names based on conditions.Bạn có thể sử dụng phương thức
Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
03 có sẵn trong đối tượng chuỗi [] trên danh sách tên cột. Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
04 được sử dụng để xác định các cột bằng cách sử dụng tên.get column names which have the value 5 in any cell, then you can use the below example.Đoạn trích
df.columns.values.tolist[]
3Bạn có thể thấy tiêu đề cột có sẵn ở vị trí
df.columns.values.tolist[]
7 và df.columns.values.tolist[]
8.Đầu ra
df.columns.values.tolist[]
4Đây là cách bạn có thể nhận được nhiều tiêu đề cột bằng chỉ mục.
Tiếp theo, bạn sẽ học cách có được các cột bắt đầu với một
Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
01 cụ thể.Gấu trúc nhận được tên cột bắt đầu bằng
Trong phần này, bạn sẽ học cách lấy tên cột bắt đầu bằng một chữ
Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
01 cụ thể.get column names with NaN.Bạn có thể sử dụng phương thức
Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
03 có sẵn trong đối tượng chuỗi [] trên danh sách tên cột. Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
04 được sử dụng để xác định các cột bằng cách sử dụng tên.
05 sẽ mang lại các cột bắt đầu bằng Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
06 và Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
07 sẽ trả về tất cả các cột được trả về bởi Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
03. Sau đó, bạn có thể nhận tên cột bằng thuộc tính Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
9. array[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'], dtype=object]
df.columns.values.tolist[]
5Đầu ra
df.columns.values.tolist[]
6Tất cả các cột bắt đầu bằng một sẽ được hiển thị dưới dạng
10. Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
df.columns.values.tolist[]
7Đầu ra
df.columns.values.tolist[]
6Đây là cách bạn có thể nhận được tên cột bắt đầu bằng một chữ
Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
01 cụ thể.Tiếp theo, bạn sẽ học cách lấy tên cột dựa trên các điều kiện.
Gấu trúc nhận được tên cột dựa trên điều kiện
Trong phần này, bạn sẽ học cách lấy tên cột dựa trên các điều kiện.get column names with duplicate values. This can be useful when you want to identify the columns which have duplicates.
Điều này có thể hữu ích khi bạn muốn xác định các cột có chứa các giá trị cụ thể. Nó còn được gọi là nhận tên cột theo giá trị.
Ví dụ: nếu bạn cần lấy tên cột có giá trị 5 trong bất kỳ ô nào, thì bạn có thể sử dụng ví dụ dưới đây.
Đoạn trích
df.columns.values.tolist[]
9Đầu ra
['product_name',
'Unit_Price',
'No_Of_Units',
'Available_Quantity',
'Available_Since_Date']
0Bạn có thể thấy tiêu đề cột có sẵn ở vị trí
df.columns.values.tolist[]
7 và df.columns.values.tolist[]
8.Đây là cách bạn có thể nhận được nhiều tiêu đề cột bằng chỉ mục.
Tiếp theo, bạn sẽ học cách có được các cột bắt đầu với một Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
01 cụ thể.
Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
Gấu trúc nhận được tên cột bắt đầu bằngget column names sorted in an alphabetical way.
Trong phần này, bạn sẽ học cách lấy tên cột bắt đầu bằng một chữ
Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
01 cụ thể.Bạn có thể sử dụng phương thức
Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
03 có sẵn trong đối tượng chuỗi [] trên danh sách tên cột.Đoạn trích
['product_name',
'Unit_Price',
'No_Of_Units',
'Available_Quantity',
'Available_Since_Date']
1Bạn có thể thấy tiêu đề cột có sẵn ở vị trí
df.columns.values.tolist[]
7 và df.columns.values.tolist[]
8.Đầu ra
['product_name',
'Unit_Price',
'No_Of_Units',
'Available_Quantity',
'Available_Since_Date']
2Đây là cách bạn có thể nhận được nhiều tiêu đề cột bằng chỉ mục.
Tiếp theo, bạn sẽ học cách có được các cột bắt đầu với một Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
01 cụ thể.
Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
Gấu trúc nhận được tên cột bắt đầu bằng
Trong phần này, bạn sẽ học cách lấy tên cột bắt đầu bằng một chữ
Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
01 cụ thể.how to show all columns of a dataframe in the output console. Bạn có thể sử dụng phương thức
Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
03 có sẵn trong đối tượng chuỗi [] trên danh sách tên cột. Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
04 được sử dụng để xác định các cột bằng cách sử dụng tên.
Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity',
'Available_Since_Date'],
dtype='object']
05 sẽ mang lại các cột bắt đầu bằngIndex[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity', 'Available_Since_Date'], dtype='object']
06 vàIndex[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity', 'Available_Since_Date'], dtype='object']
07 sẽ trả về tất cả các cột được trả về bởiIndex[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity', 'Available_Since_Date'], dtype='object']
03. Sau đó, bạn có thể nhận tên cột bằng thuộc tínhIndex[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity', 'Available_Since_Date'], dtype='object']
9.array[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity', 'Available_Since_Date'], dtype=object]
- Tất cả các cột bắt đầu bằng một sẽ được hiển thị dưới dạng
10.Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity', 'Available_Since_Date'], dtype='object']
- Đây là cách bạn có thể nhận được tên cột bắt đầu bằng một chữ
01 cụ thể.Index[['product_name', 'Unit_Price', 'No_Of_Units', 'Available_Quantity', 'Available_Since_Date'], dtype='object']
- Tiếp theo, bạn sẽ học cách lấy tên cột dựa trên các điều kiện.