import pandas as pdimport matplotlib.pyplot as pltimport osplt.rcParams['font.sans-serif']=['SimHei']plt.rcParams['axes.unicode_minus']=Falsedef dataDescribeVisualization(): while True: fileName=input('請輸入要打開的文件名presidential_polls_clinton_state_mean_lable.csv:') try: df_count=pd.read_csv(fileName,encoding='cp936') df_count=df_count.columns['Label'] df_count=df_count.value_counts() print(df_count) plt.figure() count_cut_counts.plot(kind='bar',figsize=(12,8)) plt.plot(df_count['Label'],df_count['個數'],label='個數',color='blue') plt.xlabel("Label",fontsize=12)#設置x軸標簽 plt.ylabel("個數")#設置y軸標簽 plt.xticks(OneSup, TwoSup, ThreeSup, FourSup)#設置x軸刻度 plt.title('列Lable的個數統計柱狀圖') plt.legend(figsize=16)#顯示圖例並設置字號 plt.savefig('presidential_polls_clinton_state_support.png',dpi=300) plt.show() print("任務6執行成功!") break except Exception as e: print(e)dataDescribeVisualization()import pandas as pdimport matplotlib.pyplot as pltimport osplt.rcParams['font.sans-serif']=['SimHei']plt.rcParams['axes.unicode_minus']=Falsedef dataDescribeVisualization(): while True: fileName=input('請輸入要打開的文件名presidential_polls_clinton_state_mean_lable.csv:') try: df_count=pd.read_csv(fileName,encoding='cp936') df_count=df_count.columns['Label'] df_count=df_count.value_counts() print(df_count) plt.figure() count_cut_counts.plot(kind='bar',figsize=(12,8)) plt.plot(df_count['Label'],df_count['個數'],label='個數',color='blue') plt.xlabel("Label",fontsize=12)#設置x軸標簽 plt.ylabel("個數")#設置y軸標簽 plt.xticks(OneSup, TwoSup, ThreeSup, FourSup)#設置x軸刻度 plt.title('列Lable的個數統計柱狀圖') plt.legend(figsize=16)#顯示圖例並設置字號 plt.savefig('presidential_polls_clinton_state_support.png',dpi=300) plt.show() print("任務6執行成功!") break except Exception as e: print(e)dataDescribeVisualization()
報錯:only integers, slices (:
), ellipsis (...
), numpy.newaxis (None
) and integer or boolean arrays are valid indices