程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

How Python accesses the number of elements in a column in a CSV file

編輯:Python

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(' Please enter a file name to open 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[' Number '],label=' Number ',color='blue') plt.xlabel("Label",fontsize=12)# Set up x Axis labels plt.ylabel(" Number ")# Set up y Axis labels plt.xticks(OneSup, TwoSup, ThreeSup, FourSup)# Set up x Axis scale plt.title(' Column Lable Number statistical histogram of ') plt.legend(figsize=16)# Display the legend and set the font size plt.savefig('presidential_polls_clinton_state_support.png',dpi=300) plt.show() print(" Mission 6 Successful implementation !") 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(' Please enter a file name to open 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[' Number '],label=' Number ',color='blue') plt.xlabel("Label",fontsize=12)# Set up x Axis labels plt.ylabel(" Number ")# Set up y Axis labels plt.xticks(OneSup, TwoSup, ThreeSup, FourSup)# Set up x Axis scale plt.title(' Column Lable Number statistical histogram of ') plt.legend(figsize=16)# Display the legend and set the font size plt.savefig('presidential_polls_clinton_state_support.png',dpi=300) plt.show() print(" Mission 6 Successful implementation !") break except Exception as e: print(e)dataDescribeVisualization()
Report errors :only integers, slices (:), ellipsis (...), numpy.newaxis (None) and integer or boolean arrays are valid indices


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved