简体   繁体   中英

Display Whole Matrix in Python with Pandas

I'd like to print a matrix that I've created with Numpy first and then I transformed in with Pandas.

It works fine except that it doesn't print the entire Matrix, but it gives me ... (maybe because it doesn't fit into the terminal(?). I do not know.

def build_transition_matrix(self):
    """
    Method which build the Transition Matrix with the list of tags computed earlier
    Returns
    -------
    :returns transition matrix with all the probabilities displayed in a matrix
    :rtype DataFrame
    """
    transition_matrix = np.zeros((len(self.tags_list), len(self.tags_list)), dtype='float64')
    print("MATRIX INITIALIZED")
    print("-------------------------------------------")
    for rows, tag1 in enumerate(list(self.tags_list)):
        for cols, tag2 in enumerate(list(self.tags_list)):
            transition_matrix[rows, cols] = self.transition_probability(tag2, tag1)[0]/self.transition_probability(tag2, tag1)[1]
    pretty_transition_matrix = pd.DataFrame(transition_matrix, columns=list(self.tags_list), index=list(self.tags_list))
    display(pretty_transition_matrix)
    return pretty_transition_matrix

This is the result:

在此处输入图像描述

set these 4 options:

pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None)
pd.set_option('display.width', None)
pd.set_option('display.max_colwidth', -1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM