Trực quan hóa dữ liệu là kỹ thuật được sử dụng để cung cấp những hiểu biết sâu sắc về dữ liệu bằng cách sử dụng các tín hiệu trực quan như đồ thị, biểu đồ, bản đồ và nhiều loại khác. Điều này rất hữu ích vì nó giúp hiểu trực quan và dễ hiểu về số lượng lớn dữ liệu và do đó đưa ra quyết định tốt hơn về nó. Khi chúng tôi sử dụng một số lượng lớn bộ dữ liệu thì nó bị cắt ngắn. Trong bài viết này, chúng tôi sẽ xem cách in toàn bộ bản dữ liệu Pandas hoặc sê -ri mà không bị cắt. & NBSP;a print large number of a dataset then it truncates.In this article, we are going to see how to print the entire pandas Dataframe or Series without Truncation.
Theo mặc định, khung dữ liệu hoàn chỉnh không được in nếu độ dài vượt quá độ dài mặc định, đầu ra được cắt ngắn như hình dưới đây: & nbsp;
Python3
import
numpy as np
from
sklearn.datasets
import
load_iris
import
pandas as pd
data
=
numpy as np
0
numpy as np
1=
numpy as np
3
numpy as np
4numpy as np
5=
numpy as np
7
numpy as np
8
Output:
Có 4 phương pháp để in toàn bộ gấu trúc DataFrame: 4 methods to Print the entire pandas Dataframe:
- Sử dụng phương thức to_String []
- Sử dụng phương thức pd.option_context []
- Sử dụng phương thức pd.set_options []
- Sử dụng phương thức PD.TO_markdown []
Phương pháp 1: Sử dụng To_String []
Mặc dù phương pháp này là đơn giản nhất, nhưng không nên cho các bộ dữ liệu rất lớn [theo thứ tự hàng triệu] vì nó chuyển đổi toàn bộ khung dữ liệu thành một đối tượng chuỗi nhưng hoạt động rất tốt cho các khung dữ liệu cho kích thước theo thứ tự hàng ngàn.
Cú pháp: dataFrame.to_String [buf = none, cột = none, col_space = none, header = true, index = true, na_rep = 'nan', định dạng Không, Max_cols = none, 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, index_names=True, justify=None, max_rows=None, max_cols=None, show_dimensions=False, decimal=’.’, line_width=None]
Code:
Python3
import
numpy as np
from
sklearn.datasets
import
load_iris
import
pandas as pd
data
=
numpy as np
0
numpy as np
1=
numpy as np
3
numpy as np
4numpy as np
5=
numpy as np
7
sklearn.datasets
7
Output:
Có 4 phương pháp để in toàn bộ gấu trúc DataFrame:
Sử dụng phương thức to_String []option_context[] method and set_option[] methods. Both the methods are identical with one difference that later one changes the settings permanently and the former do it only within the context manager scope.
Sử dụng phương thức pd.option_context [] pandas.option_context[*args]
Code:
Python3
import
numpy as np
from
sklearn.datasets
import
load_iris
import
pandas as pd
data
=
numpy as np
0
numpy as np
1=
numpy as np
3
numpy as np
4numpy as np
5=
numpy as np
7
load_iris
6load_iris
7load_iris
8load_iris
9import
0
import
1import
2load_iris
8load_iris
9import
0
import
1import
7load_iris
8import
9import
0
import
1pandas as pd
2
pandas as pd
3pandas as pd
4pandas as pd
5
Output:
Explanation:
Có 4 phương pháp để in toàn bộ gấu trúc DataFrame:
Sử dụng phương thức to_String []
Sử dụng phương thức pd.option_context []
Sử dụng phương thức pd.set_options []
Sử dụng phương thức PD.TO_markdown []pd.reset_option[‘all’] method has to be used to revert the changes.
Phương pháp 1: Sử dụng To_String [] pandas.set_option[pat, value]
Code:
Python3
import
numpy as np
from
sklearn.datasets
import
load_iris
import
pandas as pd
data
=
numpy as np
0
numpy as np
1=
numpy as np
3
numpy as np
4numpy as np
5=
numpy as np
7
=
4load_iris
7load_iris
8load_iris
9=
8
=
4import
2load_iris
8load_iris
9=
8
=
4numpy as np
05load_iris
8load_iris
9=
8
Có 4 phương pháp để in toàn bộ gấu trúc DataFrame:
numpy as np
8
pandas as pd
4numpy as np
17numpy as np
18=
8
numpy as np
20numpy as np
21=
8
numpy as np
8
Output:
Sử dụng phương thức to_String []
Sử dụng phương thức pd.option_context []
Sử dụng phương thức pd.set_options []DataFrame.to_markdown[buf=None, mode=’wt’, index=True,, **kwargs]
Code:
Python3
import
numpy as np
from
sklearn.datasets
import
load_iris
import
pandas as pd
data
=
numpy as np
0
numpy as np
1=
numpy as np
3
numpy as np
4numpy as np
5=
numpy as np
7
pandas as pd
4numpy as np
43
Output: