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

Grouping CSV files by month with pandas and time libraries

編輯:Python
The phenomenon and background of the problem

About using pandas\time\matplotlib The library will Intel and IBM The average value of the opening price of each month of the company in the past year is drawn in a chart ( use subplot or subplots() function )

import pandas as pd
import matplotlib.pyplot as plt
import time

def create_aveg_open(stock_code):
quotesdf_ori=pd.read_csv('step1/'+stock_code+'.csv',index_col=[0])

# Please add the code here , Complete the output as required

Begin
meanopen=quotesdf_ori.groupby('month').open.mean()
End
return meanopen 

def plot():
open1 = create_aveg_open('INTC')
open2 = create_aveg_open('IBM')
plt.figure(figsize=(10,10),dpi=100)

# Please add the code here , Complete the output as required

Begin
x1=open1.indexy1=open1x2=open2.indexy2=open2plt.subplpt(211)plt.plot(x1,y1,color="r",marker="o")plt.subplpt(212)plt.plot(x1,y1,color="g",marker="o")
End
plt.show()plt.savefig( 'step1/outfile/sub.png' )plt.close()
Operation results and error reporting contents

Do not know, such as grouping month

My solution ideas and tried methods
What I want to achieve

Ability to display line charts grouped by month


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