2016-10-10 25 views
-1

我是一名Python初學者,在我們的大學他們分配了一個項目,即使用pandas python來顯示我們系的時間表。但是我的程序顯示爲菜單驅動的程序。但問題是Iam不能夠顯示我的時間表在網格模式中使用頭()如果其他循環..可以讓我知道我在哪裏我錯了.. ?? 示例代碼:pandas python using head()通用函數

import pandas as pd 
import numpy as np 

loop=1 
while loop==1: 
    print('WELCOME TO CBIT') 
    print('1.IT 2') 
    print('2.EXIT') 
    print() 
    choice=input('Enter ur choice') 
    choice=int(choice) 
    if choice==1: 
     df=input('tt is') 
     df=pd.read_excel('Book1.xlsx') 
     df.head() 
    elif choice==2: 
     loop=0 

回答

0

使用此代碼。它會工作。在使用此代碼之前,請轉到命令提示符並編寫執行此命令pip install xlrd我相信它會工作。

import pandas as pd 
import numpy as np 

loop=1 
while loop==1: 
    print('WELCOME TO CBIT') 
    print('1.IT 2') 
    print('2.EXIT') 
    choice=int(raw_input('Input:')) 
    if choice==1: 
     #df=input('tt is') 
     df=pd.read_excel('filename.xlsx') #enter file name here 
     print(df) 
     #df.head() 
    elif choice==2: 
     loop=0 
+0

如果它解決了你的問題,那麼接受答案,並upvote它 –

+0

謝謝Sir.But我希望我的輸出顯示帶邊框線Sir.I使用head()individual.ie時通過使用邊界線得到表代碼:import pandas as pd import numpy as np df = pd.read_excel('filename.xlsx)df.head()。但在菜單驅動程序中使用此代碼時,我沒有獲取網格模式中的輸出。輸出,但沒有任何線。 –

+0

熊貓不能一次顯示完整的數據幀 –

0

添加打印語句:print(df.head())。如果你正在尋找一個更好的顯示器,你可以看看pprint