How do I expand the output display to see more columns of a pandas DataFrame?

后端 未结 19 1615
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 00:37

Is there a way to widen the display of output in either interactive or script-execution mode?

Specifically, I am using the describe() function on a pand

19条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 01:08

    import pandas as pd
    pd.set_option('display.max_columns', 100)
    pd.set_option('display.width', 1000)
    
    SentenceA = "William likes Piano and Piano likes William"
    SentenceB = "Sara likes Guitar"
    SentenceC = "Mamoosh likes Piano"
    SentenceD = "William is a CS Student"
    SentenceE = "Sara is kind"
    SentenceF = "Mamoosh is kind"
    
    
    bowA = SentenceA.split(" ")
    bowB = SentenceB.split(" ")
    bowC = SentenceC.split(" ")
    bowD = SentenceD.split(" ")
    bowE = SentenceE.split(" ")
    bowF = SentenceF.split(" ")
    
    # Creating a set consisted of all words
    
    wordSet = set(bowA).union(set(bowB)).union(set(bowC)).union(set(bowD)).union(set(bowE)).union(set(bowF))
    print("Set of all words is: ", wordSet)
    
    # Initiating dictionary with 0 value for all BOWs
    
    wordDictA = dict.fromkeys(wordSet, 0)
    wordDictB = dict.fromkeys(wordSet, 0)
    wordDictC = dict.fromkeys(wordSet, 0)
    wordDictD = dict.fromkeys(wordSet, 0)
    wordDictE = dict.fromkeys(wordSet, 0)
    wordDictF = dict.fromkeys(wordSet, 0)
    
    for word in bowA:
        wordDictA[word] += 1
    for word in bowB:
        wordDictB[word] += 1
    for word in bowC:
        wordDictC[word] += 1
    for word in bowD:
        wordDictD[word] += 1
    for word in bowE:
        wordDictE[word] += 1
    for word in bowF:
        wordDictF[word] += 1
    
    # Printing Term frequency
    
    print("SentenceA TF: ", wordDictA)
    print("SentenceB TF: ", wordDictB)
    print("SentenceC TF: ", wordDictC)
    print("SentenceD TF: ", wordDictD)
    print("SentenceE TF: ", wordDictE)
    print("SentenceF TF: ", wordDictF)
    
    print(pd.DataFrame([wordDictA, wordDictB, wordDictB, wordDictC, wordDictD, wordDictE, wordDictF]))
    

    OutPut:

       CS  Guitar  Mamoosh  Piano  Sara  Student  William  a  and  is  kind  likes
    0   0       0        0      2     0        0        2  0    1   0     0      2
    1   0       1        0      0     1        0        0  0    0   0     0      1
    2   0       1        0      0     1        0        0  0    0   0     0      1
    3   0       0        1      1     0        0        0  0    0   0     0      1
    4   1       0        0      0     0        1        1  1    0   1     0      0
    5   0       0        0      0     1        0        0  0    0   1     1      0
    6   0       0        1      0     0        0        0  0    0   1     1      0
    

提交回复
热议问题