python运用pandas对数据进行可视化,分析与预测不同国家的肉类消耗量

由题目可知,主要运用到了pandas库,结合GUI界面,进行数据分析与数据可视化.
博客似乎不能上传文件,所以我的文件没有上传
代码如下:

import matplotlib.pyplot as plt  
import pandas as pd  
import tkinter as tk  
import tkinter.ttk as ttk   
  
df=pd.read_csv("meat_consumption_worldwide.csv")  
  
class pad:  
    def get_countery(self):  
        self.country=[]  
        for item in df["LOCATION"]:  
            if item not in self.country:                  
               self.country.append(item)  
    def get_information(self,event):  
        coutry_name=self.__varbox.get()  
        begin=0  
        end=0  
        first=True  
        #######获取该国家的始末行数#########  
        for item in df["LOCATION"]:   
            if first: begin+=1  
            end+=1  
            if item ==coutry_name:  
                first=False  
            if first==False and item!=coutry_name:  
                break  
        self.dfname=df[begin-1:end-1]  
        self.draw_plt()  
    def draw_plt(self):  
        #######获取牛肉###############  
        begin=0  
        end=0  
        first=True  
        for item in df["SUBJECT"]:   
            if first: begin+=1  
            end+=1  
            if item =="BEEF":  
                first=False  
            if first==False and item!="BEEF":  
                break  
        self.dfbeef=df[begin-1:end-1]  
        self.dfbeef=self.dfbeef.set_index("TIME")  
        #############获取猪肉#########  
        begin=0  
        end=0  
        first=True  
        for item in df["SUBJECT"]:   
            if first: begin+=1  
            end+=1  
            if item =="PIG":  
                first=False  
            if first==False and item!="PIG":  
                break  
        self.dfpig=df[begin-1:end-1]  
        self.dfpig=self.dfpig.set_index("TIME")  
        ##############获取家禽肉############  
        begin=0  
        end=0  
        first=True  
        for item in df["SUBJECT"]:   
            if first: begin+=1  
            end+=1  
            if item =="POULTRY":  
                first=False  
            if first==False and item!="POULTRY":  
                break  
        self.dfpoultry=df[begin-1:end-1]  
        self.dfpoultry=self.dfpoultry.set_index("TIME")  
        ##########获取羊肉#########  
        begin=0  
        end=0  
        first=True  
        for item in df["SUBJECT"]:   
            if first: begin+=1  
            end+=1  
            if item =="SHEEP":  
                first=False  
            if first==False and item!="SHEEP":  
                break  
        self.dfsheep=df[begin-1:end-1]  
        self.dfsheep=self.dfsheep.set_index("TIME")  
        self.dfbeef.rename(columns={"Value" :"BEEF"},inplace=True)  
        self.dfbeef["PIG"]=self.dfpig["Value"]  
        self.dfbeef["POULTRY"]=self.dfpoultry["Value"]  
        self.dfbeef["SHEEP"]=self.dfsheep["Value"]  
        self.dfbeef.plot()  
        plt.show()  
    def __init__(self):  
        self.__window=tk.Tk()  
        self.__window.geometry("400x400")  
        self.__window.title("国家饮食情况选择器")  
        self.__window.resizable(height=True,width=True)  
        self.get_countery()  
        self.__varbox=tk.StringVar()      
        self.__lab1=tk.Label(self.__window,text="请输入国家名称",font="楷体").place(x=120,y=20)  
        self.__combox=ttk.Combobox(self.__window,textvariable=self.__varbox,value=tuple(self.country))  
        self.__combox.current(0)  
        self.__combox.place(x=120,y=80)  
        self.__combox.bind("<<ComboboxSelected>>",self.get_information)            
        self.__window.mainloop()  
  
  
def main():  
    pds=pad()  
      
if "__name__"==main():  
    main()  

运行截图如下:
在这里插入图片描述
在这里插入图片描述
本来想上传视频的,但是还要上传到腾旭视频上,好麻烦。

希望大家多多指教啦!!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值