Làm thế nào để bạn in toàn bộ khung dữ liệu trong python?

Làm cách nào để hiển thị hoặc in đẹp toàn bộ Khung dữ liệu/Sê-ri gấu trúc mà không cắt bớt hàng, cột hoặc văn bản cột? . Ví dụ: theo mặc định, chiều rộng của cột bị cắt ngắn ở 50 ký tự

Để In đẹp toàn bộ Khung dữ liệu hoặc Sê-ri Pandas, bạn cần đặt một số tùy chọn bằng cách sử dụng các phương pháp ________ 00, ________ 01 và


import pandas as pd
technologies = {
  'id' :[101,102,103],
  "Proverb":["Be the change that you wish to see in the world",
      "Everyone thinks of changing the world, but no one thinks of changing himself.",
      "The purpose of our lives is to be happy."]
   }
df = pd.DataFrame[technologies]
print[df]
2

Một số thuật ngữ quan trọng để sử dụng trong các tùy chọn in đẹp được thảo luận bên dưới

  • 
    import pandas as pd
    technologies = {
      'id' :[101,102,103],
      "Proverb":["Be the change that you wish to see in the world",
          "Everyone thinks of changing the world, but no one thinks of changing himself.",
          "The purpose of our lives is to be happy."]
       }
    df = pd.DataFrame[technologies]
    print[df]
    
    3 Nó xác định tổng số cột pandas nên in. Nếu Không được chuyển dưới dạng đối số, tất cả các cột được in
  • 
    import pandas as pd
    technologies = {
      'id' :[101,102,103],
      "Proverb":["Be the change that you wish to see in the world",
          "Everyone thinks of changing the world, but no one thinks of changing himself.",
          "The purpose of our lives is to be happy."]
       }
    df = pd.DataFrame[technologies]
    print[df]
    
    4 Nó xác định tổng số hàng mà gấu trúc nên in. Nếu Không được truyền dưới dạng đối số, tất cả các hàng sẽ được in
  • 
    import pandas as pd
    technologies = {
      'id' :[101,102,103],
      "Proverb":["Be the change that you wish to see in the world",
          "Everyone thinks of changing the world, but no one thinks of changing himself.",
          "The purpose of our lives is to be happy."]
       }
    df = pd.DataFrame[technologies]
    print[df]
    
    5 Đây cũng là một tùy chọn quan trọng xác định độ rộng của màn hình theo ký tự. Nếu được đặt thành Không, gấu trúc sẽ tự động phát hiện chính xác chiều rộng
  • 
    import pandas as pd
    technologies = {
      'id' :[101,102,103],
      "Proverb":["Be the change that you wish to see in the world",
          "Everyone thinks of changing the world, but no one thinks of changing himself.",
          "The purpose of our lives is to be happy."]
       }
    df = pd.DataFrame[technologies]
    print[df]
    
    6 Kiểm soát căn chỉnh tiêu đề cột
  • 
    import pandas as pd
    technologies = {
      'id' :[101,102,103],
      "Proverb":["Be the change that you wish to see in the world",
          "Everyone thinks of changing the world, but no one thinks of changing himself.",
          "The purpose of our lives is to be happy."]
       }
    df = pd.DataFrame[technologies]
    print[df]
    
    7 Độ chính xác của đầu ra dấu phẩy động về số lượng vị trí sau dấu thập phân, đối với định dạng thông thường cũng như ký hiệu khoa học

1. Ví dụ nhanh về Sê-ri/DataFrame của Pretty Print Pandas

Nếu bạn đang vội, bên dưới là một số ví dụ nhanh về cách in đẹp toàn bộ Sê-ri/Khung dữ liệu của gấu trúc

________số 8

Python pandas được sử dụng rộng rãi cho các ứng dụng khoa học dữ liệu/phân tích dữ liệu và máy học. Nó được xây dựng dựa trên một gói phổ biến khác có tên Numpy, cung cấp khả năng tính toán khoa học bằng Python. pandas DataFrame là cấu trúc dữ liệu được gắn nhãn 2 chiều với các hàng và cột [các cột có thể có các loại khác nhau như số nguyên, chuỗi, float, Không có, đối tượng Python e. t. c]. Bạn có thể coi nó như một bảng tính excel hoặc bảng SQL

Hãy tạo một Pandas tạo DataFrame từ từ điển Python trong đó 


import pandas as pd
technologies = {
  'id' :[101,102,103],
  "Proverb":["Be the change that you wish to see in the world",
      "Everyone thinks of changing the world, but no one thinks of changing himself.",
      "The purpose of our lives is to be happy."]
   }
df = pd.DataFrame[technologies]
print[df]
8 là 

import pandas as pd
technologies = {
  'id' :[101,102,103],
  "Proverb":["Be the change that you wish to see in the world",
      "Everyone thinks of changing the world, but no one thinks of changing himself.",
      "The purpose of our lives is to be happy."]
   }
df = pd.DataFrame[technologies]
print[df]
9,

import pandas as pd
technologies = {
  'id' :[101,102,103],
  "Proverb":["Be the change that you wish to see in the world",
      "Everyone thinks of changing the world, but no one thinks of changing himself.",
      "The purpose of our lives is to be happy."]
   }
df = pd.DataFrame[technologies]
print[df]
10,

import pandas as pd
technologies = {
  'id' :[101,102,103],
  "Proverb":["Be the change that you wish to see in the world",
      "Everyone thinks of changing the world, but no one thinks of changing himself.",
      "The purpose of our lives is to be happy."]
   }
df = pd.DataFrame[technologies]
print[df]
11‘,

import pandas as pd
technologies = {
  'id' :[101,102,103],
  "Proverb":["Be the change that you wish to see in the world",
      "Everyone thinks of changing the world, but no one thinks of changing himself.",
      "The purpose of our lives is to be happy."]
   }
df = pd.DataFrame[technologies]
print[df]
12 và 

import pandas as pd
technologies = {
  'id' :[101,102,103],
  "Proverb":["Be the change that you wish to see in the world",
      "Everyone thinks of changing the world, but no one thinks of changing himself.",
      "The purpose of our lives is to be happy."]
   }
df = pd.DataFrame[technologies]
print[df]
13 được coi là một danh sách các giá trị khóa tương ứng


import pandas as pd
technologies = {
  'id' :[101,102,103],
  "Proverb":["Be the change that you wish to see in the world",
      "Everyone thinks of changing the world, but no one thinks of changing himself.",
      "The purpose of our lives is to be happy."]
   }
df = pd.DataFrame[technologies]
print[df]

Sản lượng dưới sản lượng

1. Hiển thị bản in đẹp Toàn bộ nội dung khung dữ liệu Pandas

Lưu ý rằng Khung dữ liệu của chúng tôi ở trên hiển thị khá nhiều hàng, cột nhưng văn bản ở hàng 2 bị cắt bớt ở 50 ký tự. Nếu bạn có khung dữ liệu quá lớn và bản in không hiển thị toàn bộ Khung dữ liệu, hãy sử dụng bản in sau khi chuyển đổi Khung dữ liệu thành Chuỗi


import pandas as pd
technologies = {
  'id' :[101,102,103],
  "Proverb":["Be the change that you wish to see in the world",
      "Everyone thinks of changing the world, but no one thinks of changing himself.",
      "The purpose of our lives is to be happy."]
   }
df = pd.DataFrame[technologies]
print[df]
1

Đây là cách dễ nhất để hiển thị toàn bộ DataFrame lên bảng điều khiển hoặc thiết bị đầu cuối mà không cần cắt bớt. Bằng cách chạy đoạn mã trên, bạn sẽ nhận được đầu ra bên dưới

2. sử dụng pd. option_context[] thành Khung dữ liệu Pandas in đẹp

Trong trường hợp nếu bạn không thể sử dụng phương pháp trên, bạn cần thay đổi cài đặt của pandas bằng cách sử dụng option_context[] và trong bối cảnh câu lệnh. Mã sau in DataFrame có bốn hàng, tất cả các cột trong một hàng có tiêu đề cột được căn trái và làm tròn số vị trí sau dấu thập phân cho mỗi giá trị nổi


import pandas as pd
technologies = {
  'id' :[101,102,103],
  "Proverb":["Be the change that you wish to see in the world",
      "Everyone thinks of changing the world, but no one thinks of changing himself.",
      "The purpose of our lives is to be happy."]
   }
df = pd.DataFrame[technologies]
print[df]
7

Sản lượng dưới sản lượng


import pandas as pd
technologies = {
  'id' :[101,102,103],
  "Proverb":["Be the change that you wish to see in the world",
      "Everyone thinks of changing the world, but no one thinks of changing himself.",
      "The purpose of our lives is to be happy."]
   }
df = pd.DataFrame[technologies]
print[df]
8

4. sử dụng pd. set_options[] để hiển thị vài cột của DataFrame

Hãy sử dụng ví dụ tương tự ở trên nhưng bằng cách sử dụng chức năng


import pandas as pd
technologies = {
  'id' :[101,102,103],
  "Proverb":["Be the change that you wish to see in the world",
      "Everyone thinks of changing the world, but no one thinks of changing himself.",
      "The purpose of our lives is to be happy."]
   }
df = pd.DataFrame[technologies]
print[df]
14, Tùy thuộc vào tùy chọn bạn sử dụng, bạn cần gọi chức năng này để thay đổi cài đặt. Hãy sử dụng tùy chọn này để xem tất cả các hàng, ba cột, tất cả các cột trong một hàng có tiêu đề cột được căn giữa và làm tròn số vị trí sau dấu thập phân cho mỗi giá trị thả nổi thành hai


import pandas as pd
technologies = {
  'id' :[101,102,103],
  "Proverb":["Be the change that you wish to see in the world",
      "Everyone thinks of changing the world, but no one thinks of changing himself.",
      "The purpose of our lives is to be happy."]
   }
df = pd.DataFrame[technologies]
print[df]
0

Sản lượng dưới sản lượng


import pandas as pd
technologies = {
  'id' :[101,102,103],
  "Proverb":["Be the change that you wish to see in the world",
      "Everyone thinks of changing the world, but no one thinks of changing himself.",
      "The purpose of our lives is to be happy."]
   }
df = pd.DataFrame[technologies]
print[df]
1

5. Sử dụng tùy chọn. hiển thị để Giảm kích thước của Khung dữ liệu Pandas

Ngoài ra, chúng ta cũng có thể sử dụng


import pandas as pd
technologies = {
  'id' :[101,102,103],
  "Proverb":["Be the change that you wish to see in the world",
      "Everyone thinks of changing the world, but no one thinks of changing himself.",
      "The purpose of our lives is to be happy."]
   }
df = pd.DataFrame[technologies]
print[df]
2 để giảm kích thước hàng và cột của Khung dữ liệu Pandas, lý tưởng nhất là in Khung dữ liệu đẹp trong bảng điều khiển. Mã sau in DataFrame có hai hàng, bốn cột, tất cả các cột trong một hàng có tiêu đề cột được căn trái và không làm tròn số vị trí sau dấu thập phân cho mỗi giá trị nổi


import pandas as pd
technologies = {
  'id' :[101,102,103],
  "Proverb":["Be the change that you wish to see in the world",
      "Everyone thinks of changing the world, but no one thinks of changing himself.",
      "The purpose of our lives is to be happy."]
   }
df = pd.DataFrame[technologies]
print[df]
3

Sản lượng dưới sản lượng


import pandas as pd
technologies = {
  'id' :[101,102,103],
  "Proverb":["Be the change that you wish to see in the world",
      "Everyone thinks of changing the world, but no one thinks of changing himself.",
      "The purpose of our lives is to be happy."]
   }
df = pd.DataFrame[technologies]
print[df]
4

6. Ví dụ hoàn chỉnh về In toàn bộ sê-ri/Khung dữ liệu đẹp


import pandas as pd
technologies = {
  'id' :[101,102,103],
  "Proverb":["Be the change that you wish to see in the world",
      "Everyone thinks of changing the world, but no one thinks of changing himself.",
      "The purpose of our lives is to be happy."]
   }
df = pd.DataFrame[technologies]
print[df]
5

7. Sự kết luận

Trong bài viết này, tôi đã giải thích cách in toàn bộ Pandas DataFrame sang bảng điều khiển hoặc thiết bị đầu cuối bằng cách sử dụng các hàm ________ 00, ________ 01 và


import pandas as pd
technologies = {
  'id' :[101,102,103],
  "Proverb":["Be the change that you wish to see in the world",
      "Everyone thinks of changing the world, but no one thinks of changing himself.",
      "The purpose of our lives is to be happy."]
   }
df = pd.DataFrame[technologies]
print[df]
2 với các ví dụ. Bạn có thể sử dụng ví dụ tương tự để in đẹp Sê-ri

Chủ Đề