Có cách nào để tôi có thể đóng băng phần đầu khung dữ liệu Pandas {như chúng ta làm trong excel}. Nếu đó là một khung dữ liệu dài với nhiều hàng, chúng ta có thể thấy tiêu đề khi chúng ta cuộn xuống !! Tôi giả định ipython máy tính xách tayFreeze header in pandas dataframe
9
A
Trả lời
0
Một giải pháp mà sẽ làm việc trên bất kỳ trình soạn là chọn những gì hàng bạn muốn xem:
df.ix[100:110] # would show you from row 101 to 110 keeping the header on top
6
Chức năng này có thể làm các trick:
from ipywidgets import interact, IntSlider
from IPython.display import display
def freeze_header(df, num_rows=30, num_columns=10, step_rows=1,
step_columns=1):
"""
Freeze the headers (column and index names) of a Pandas DataFrame. A widget
enables to slide through the rows and columns.
Parameters
----------
df : Pandas DataFrame
DataFrame to display
num_rows : int, optional
Number of rows to display
num_columns : int, optional
Number of columns to display
step_rows : int, optional
Step in the rows
step_columns : int, optional
Step in the columns
Returns
-------
Displays the DataFrame with the widget
"""
@interact(last_row=IntSlider(min=min(num_rows, df.shape[0]),
max=df.shape[0],
step=step_rows,
description='rows',
readout=False,
disabled=False,
continuous_update=True,
orientation='horizontal',
slider_color='purple'),
last_column=IntSlider(min=min(num_columns, df.shape[1]),
max=df.shape[1],
step=step_columns,
description='columns',
readout=False,
disabled=False,
continuous_update=True,
orientation='horizontal',
slider_color='purple'))
def _freeze_header(last_row, last_column):
display(df.iloc[max(0, last_row-num_rows):last_row,
max(0, last_column-num_columns):last_column])
thử nghiệm nó với:
import pandas as pd
df = pd.DataFrame(pd.np.random.RandomState(seed=0).randint(low=0,
high=100,
size=[200, 50]))
freeze_header(df=df, num_rows=10)
nó là kết quả trong (các màu sắc được tùy chỉnh trong ~/.jupyter/custom/custom.css
tệp):
Các vấn đề liên quan
- 1. Dataframe Merge in Pandas
- 2. Python Pandas Thay header với Top Row
- 3. Chuyển đổi Pandas Dataframe
- 4. Pandas DataFrame: Cách in một hàng theo chiều ngang?
- 5. Py Pandas .format (dataframe)
- 6. Chuyển đổi Pandas dataframe để Dask dataframe
- 7. Pandas: Lấy mẫu DataFrame
- 8. Pandas: dataframe duy nhất
- 9. pandas DataFrame pivoting issue
- 10. Pandas DataFrame Áp dụng
- 11. Unmelt Pandas DataFrame
- 12. Pandas thứ bậc dataframe
- 13. Pandas to_csv() tiết kiệm chậm dataframe lớn
- 14. Pandas: Tạo DataFrame từ Dòng
- 15. nhiều ô từ Pandas dataframe
- 16. Pandas Dataframe to excel sheet
- 17. Slice Pandas DataFrame by Row
- 18. Pandas dataframe Descartes tham gia
- 19. bằng len() trong Pandas dataframe
- 20. loạt thời gian seaborn từ pandas dataframe
- 21. Pandas dataframe với cột multiindex - merge mức
- 22. Pandas viết dataframe vào tệp CSV
- 23. Rẽ Pandas DataFrame các chuỗi vào histogram
- 24. Pandas: Tạo cột tổng hợp trong DataFrame
- 25. Large Pandas Dataframe xử lý song song
- 26. Pandas DataFrame giá trị cập nhật Cột với DataFrame khác
- 27. pandas dataframe cột mở rộng với sklearn
- 28. Chuyển đổi hàng sang tiêu đề cột cho Pandas DataFrame,
- 29. Pandas in ALL Dtypes
- 30. 'CSV không tồn tại' - Pandas DataFrame
bạn đã bao giờ tìm ra điều này chưa? – tmthyjames
Không, tôi không thể tìm ra – sushmit