GANDAS DATAFRAME là một cấu trúc dữ liệu dạng bảng có kích thước hai chiều, có khả năng không đồng nhất với các trục được dán nhãn [hàng và cột]. Các hoạt động số học căn chỉnh trên cả nhãn hàng và cột. Nó có thể được coi là một container giống như dict cho các đối tượng loạt. Đây là cấu trúc dữ liệu chính của gấu trúc.
Hàm Pandas DataFrame.to_string[]
kết xuất một khung dữ liệu cho đầu ra bảng thân thiện với bảng điều khiển.
Cú pháp: dataFrame.to_String [buf = none, cột = none, col_space = none, header = true, index = true Không, MAX_ROWS = Không, MAX_COLS = Không, Show_Dimensions = false, Decimal = '.', Line_width = none] DataFrame.to_string[buf=None, columns=None, col_space=None, header=True, index=True, na_rep=’NaN’, formatters=None, float_format=None, sparsify=None, index_names=True, justify=None, max_rows=None, max_cols=None, show_dimensions=False, decimal=’.’, line_width=None]
Tham số: BUF: Bộ đệm để ghi vào.Columns: tập hợp con của các cột để viết. Ghi tất cả các cột theo mặc định.col_space: Chiều rộng tối thiểu của mỗi cột.Header: Viết tên cột. Nếu một danh sách các chuỗi được đưa ra, nó được coi là bí danh cho các tên cột.index: có nên in các nhãn chỉ mục [hàng ].na_rep: Biểu diễn chuỗi của NAN để sử dụng. vị trí hoặc tên.float_format: hàm định dạng để áp dụng cho các phần tử của các cột nếu chúng là phao. Kết quả của chức năng này phải là chuỗi Unicode.SparSify: Đặt thành false cho một khung dữ liệu có chỉ mục phân cấp để in mọi khóa đa index ở mỗi hàng.index_names: In tên của các chỉ mục.MAX_Rows: Số lượng hàng tối đa để hiển thị trong Console.MAX_COLS: Số lượng cột tối đa để hiển thị trong bảng điều khiển.Show_Dimensions: Hiển thị kích thước DataFrame [số lượng hàng theo số cột] .Decimal: ký tự được công nhận là dấu phân cách thập phân, ví dụ: ‘, Ở châu Âu.line_width: chiều rộng để bọc một dòng trong các ký tự.
buf : Buffer to write to.
columns : The subset of columns to write. Writes all columns by default.
col_space : The minimum width of each column.
header : Write out the column names. If a list of strings is given, it is assumed to be aliases for the column names.
index : Whether to print index [row] labels.
na_rep : String representation of NAN to use.
formatters : Formatter functions to apply to columns’ elements by position or name.
float_format : Formatter function to apply to columns’ elements if they are floats. The result of this function must be a unicode string.
sparsify : Set to False for a DataFrame with a hierarchical index to print every multiindex key at each row.
index_names : Prints the names of the indexes.
max_rows : Maximum number of rows to display in the console.
max_cols : Maximum number of columns to display in the console.
show_dimensions : Display DataFrame dimensions [number of rows by number of columns].
decimal : Character recognized as decimal separator, e.g. ‘, ’ in Europe.
line_width : Width to wrap a line in characters.Trả về: str [hoặc unicode, tùy thuộc vào dữ liệu và tùy chọn] str [or unicode, depending on data and options]
Ví dụ #1: Sử dụng hàm DataFrame.to_string[]
để hiển thị DataFrame đã cho thành đầu ra bảng thân thiện với bảng điều khiển. Không bao gồm các nhãn chỉ mục trong đầu ra. Use DataFrame.to_string[]
function to render the given DataFrame to a console-friendly tabular output. Do not include the index labels in the output.
import
pandas as pd
Các
DataFrame.to_string[]
9import
0:[
import
2DataFrame.to_string[]
0import
4DataFrame.to_string[]
0import
6DataFrame.to_string[]
0import
8DataFrame.to_string[]
0pandas as pd
0DataFrame.to_string[]
8
DataFrame.to_string[]
9pandas as pd
3:[
pandas as pd
5DataFrame.to_string[]
0pandas as pd
7DataFrame.to_string[]
0pandas as pd
9DataFrame.to_string[]
0df
1DataFrame.to_string[]
0df
3df
4
df
5=
df
7df
8df
9=
=
1=
2=
=
4=
5
=
6=
=
8
=
9pd.DataFrame[{
0
Đầu ra:
Bây giờ chúng tôi sẽ sử dụng chức năng DataFrame.to_string[]
để hiển thị DataFrame đã cho thành đầu ra bảng thân thiện với bảng điều khiển.
pd.DataFrame[{
2=
pd.DataFrame[{
4=
pd.DataFrame[{
6=
5
=
9pd.DataFrame[{
9
Đầu ra: Như chúng ta có thể thấy trong đầu ra, hàm DataFrame.to_string[]
đã kết xuất thành công DataFrame cho đầu ra bảng thân thiện với bảng điều khiển. Biểu thị giá trị bị thiếu trong dataFrame đã cho bằng chuỗi ‘thiếu.
As we can see in the output, the
DataFrame.to_string[]
function has successfully rendered the given dataframe to the console friendly tabular output.Example #2: Use
DataFrame.to_string[]
function to render the given DataFrame to a console-friendly tabular output. Represent the missing value in the given Dataframe by the string ‘Missing’.import
pandas as pd
Các
DataFrame.to_string[]
945
0:[
45
2DataFrame.to_string[]
045
4DataFrame.to_string[]
045
6DataFrame.to_string[]
045
8DataFrame.to_string[]
0:[
5:[
8
DataFrame.to_string[]
9DataFrame.to_string[]
03:[
DataFrame.to_string[]
05DataFrame.to_string[]
0DataFrame.to_string[]
07DataFrame.to_string[]
0DataFrame.to_string[]
09DataFrame.to_string[]
045
8DataFrame.to_string[]
0df
1:[
8
df
5=
df
7df
8df
9=
=
1=
2=
=
4=
5
=
6=
=
8
=
6=
=
8
=
9pd.DataFrame[{
0
Đầu ra:
Bây giờ chúng tôi sẽ sử dụng chức năng DataFrame.to_string[]
để hiển thị DataFrame đã cho thành đầu ra bảng thân thiện với bảng điều khiển.
pd.DataFrame[{
2=
pd.DataFrame[{
4=
pd.DataFrame[{
6=
5
=
9pd.DataFrame[{
9
Đầu ra: Như chúng ta có thể thấy trong đầu ra, hàm DataFrame.to_string[]
đã kết xuất thành công DataFrame cho đầu ra bảng thân thiện với bảng điều khiển. Biểu thị giá trị bị thiếu trong dataFrame đã cho bằng chuỗi ‘thiếu.
As we can see in the output, the
DataFrame.to_string[]
function has successfully rendered the given dataframe to the console-friendly tabular output.