欢迎访问 懂农资网!权威农资专家解读,让你更懂农资!

手机版

农药使用量数据(农药污染数据)

2024-07-15 投稿人 : 懂农资网 围观 : 6340 次
农药使用量数据(农药污染数据) °èˉè?¤°?°èˉè§–°“°èˉ

°?–è?aè‘—°§‘?-|èμ‘Kaggleè?ˉ”¨°é?PesticideUseinAgriculture‰è¥—°é‰è?£è?°o?2024?’?2024?1′?o|?ˉa·423?§è?ˉ”¨…μ?-¤?¤–èˉ¥°±è?ˉ”¨…쉤?§°?μ?¥è?°ˉ?°?μLOW_ESTIMATE‰?’?é°?μHIGH_ESTIMATE‰¥?ˉ?ˉ1è¤a°?μ–1?3–1è§£é?

TwodifferentmethodswereusedtoestimatearangeofpesticideuseforallstatesexceptCalifornia.BothlowandhighestimatemethodsincorporatedproprietarysurveyedratesforUnitedStatesDepartmentofAgricultureCropReportingDistricts,buttheestimatesdifferedinhowtheytreatedsituationswhenadistrictwassurveyedandpesticideusewasnotreported.Lowestimatesassumedzerouseinthedistrictforthatpesticide;however,highestimatestreatedtheunreporteduseofpesticidesasmissingdataandestimatedthepesticideusagefromneighboringlocationswithinthesameregion.

èè¨1é?¨¨?”?é…·°oè?ˉ”¨…μ?—é?¨?°oè°¥“¤oa?a?¥a…μ?‰¥a°?μ?a–1?3¨é°?±…μ?—?èˉ¥°o?2‰”¨è?ˉ?¨°é-è?°NaNaé°?μ?a–1?3?°a?¥è?ˉ°oè?°o°?o?¤±°°—éè?‘°oè?ˉ”¨…μ?oèˉ¥°o?°?μ?

¨-?‘°?……“’–?°é¨?ˉ…ˉè|ˉ1°é…’ˉè§–èè|-|?¨a?′è·ˉˉ1°é¢?′¢è§£?-¤?¤–è¥è§|°?|?ˉ1°§?‰1ˉè§–?‘°

‰Python?‰±o“numpypandasmatplotlibseaborn?¥¤°ˉ?”¨°Python?‰±o“geopandascontextilyrasterio

è?¤°

#?ˉ…¥?‰±o“importnumpyasnpimportpandasaspdimportmatplotlib.pyplotaspltimportseabornassns#seaborn-0.9.0%matplotlibinline#è°édata2024=pd.read_csv('./2024.csv')data2024=pd.read_csv('./2024.csv')states=pd.read_csv('./dictionary.csv')#1°édata2024_states=data2024.merge(states,how='left',on=['STATE_CODE','COUNTY_CODE'])data2024_states=data2024.merge(states,how='left',on=['STATE_CODE','COUNTY_CODE'])

¨é?¢?£?-?‘¤—?‰1STATE_CODE?’?COUNTY_CODE?°éstates-‰1COUNTY?’?STATE1°?o?data2024?’?data2024¤a°é-èˉ?oSTATE_CODE?’?COUNTY_CODE¤—?‰1?ˉ‰a°é…±‰—1”ˉ¥?°…?è–o?ˉ1?o”COUNTY?’?STATE?¤—?ˉ

°?-¤?‘?ˉ¥¥‰°éo?

data2024_states.head()

data2024_states.head()

é?¢?¤aè?¨ˉ¥?°¤a?1′?o|°é‰1?—ˉè?′·|è?33?è?ˉ?COMPOUND‰?1′YEAR‰?·£STATE_CODE‰?£COUNTY_CODE‰?°?μLOW_ESTIMATE‰é°?μHIGH_ESTIMATE‰§°COUNTRY‰?’·?§°STATE‰éèè°”¨pd.DataFrame.info?°?‘?ˉ¥‘°?°?μ?LOW_ESTIMATE¨¤a?1′?o|°é-é-¨o?¤±?-£?|‘?¨°èˉ-?°èˉ?”±?o?é?¨·?12‰?¥è?ˉ”¨…μ?‰é?oˉ1?ˉ1?o”é°?μ?HIGH_ESTIMATE?°±…?ˉéè′è?‘°oè?ˉ”¨…μ?μ—?“”±?o°?μ‰1o?‰?‰1‰1‰1ˉ1?o”?o?¤±·ˉ”褧‰¥‘1?‰“—?ˉ1?…?èè·‰”é?¤?-‰?…–è§°?…“è?ˉ′¥?°…¢o-1è?¨…?1‰”¨0ˉ?o?…èo·2‰a·2?¥”èˉ¥è?ˉ”¨a0a1‰‰

#……o?¤±data2024_states['LOW_ESTIMATE']=data2024_states.LOW_ESTIMATE.fillna(-1)data2024_states['LOW_ESTIMATE']=data2024_states.LOW_ESTIMATE.fillna(-1)#¥éa?print(data2024_states[data2024_states.LOW_ESTIMATE.isnull()==True].size)print(data2024_states[data2024_states.LOW_ESTIMATE.isnull()==True].size)°èˉè§–

èè‘°§ˉ1°éèè?è–?’ˉè§–

é|–?…‘è|°—?‰1ˉèè|μ±1?‘è|?èˉ”è?ˉ‰èè¨è?ˉ’°èˉ¥–?a?±‘-…è|…‰1ˉ—?…-é°èˉ¥?o?ˉ1?ˉ1?ˉ”?±èèˉ”è±°‰‰—¤a1′ˉ1?o”?ˉ”è1ˉ¥¢ˉ”è?‰·…ˉ1?o”£o°‰1?ˉé‰1±ˉ¥?‰1?o?-¤°?ˉè§–

?ˉ1—?‰1±èè|μ±o?”ˉ?°‰1é°è‘…?è|?èˉ¨1′·…μè—ˉè|°ˉè°ˉ?……a?′é?2a?o¥oa‰?°·?”¤§?‰?è‰?–°?‘°?’è§£?ˉ”?|

sns.catplot(x="STATE",y="HIGH_ESTIMATE",kind="bar",data=data2024_states)fig=plt.gcf()fig.set_size_inches(20,5)

-?‘ˉ·è?ˉ”¨é°?μ?13’?95%oé—′ˉ¥‘°?¨a¤°?·è?ˉ?13?°?μˉè?…è4000è?”¨o°°‘·-“°oèo?3o‰¥?o?o–è?ˉ”¨é¨è°′?13·—ˉ1?ˉ”é°?μ·?ˉ¥?|±?

temp_l=data2024_states[data2024_states.LOW_ESTIMATE!=-1].copy()temp_l.loc[:,'Estimate_method']='LOW_ESTIMATE'temp_l.loc[:,'estimate']=temp_l.LOW_ESTIMATEtemp_h=data2024_statestemp_h.loc[:,'Estimate_method']='HIGH_ESTIMATE'temp_h.loc[:,'estimate']=temp_l.HIGH_ESTIMATEtemp=pd.concat([temp_l,temp_h],axis=0).sort_values('STATE')plt.figure(figsize=(30,8))sns.boxplot(x="STATE",y="estimate",hue='Estimate_method',data=temp)plt.yscale('log')plt.xlabel("State")plt.ylabel("Usagepesticide-use")plt.title("Pesticide-useinallstatesinyear2024")plt.grid()

ˉ2024?1′?o|?”¨…μˉ¥‘°è?oˉ?“a?§°?μ“?·è?ˉ”¨é鉅-è?…è10^6106”¨é·?°±o°¨CAFLID?’?WA?a?·-oμˉ?”¨log?°?o|–è‰1”?…–?‰‰?·è?ˉ?”¨ééè°‘?o?èa?·…-é?è?ˉ?”¨éˉ1°‘¤§é°o?10^4104‰·a‰¥è?aCTNHRI?’?VT?a?·-?°?|-¤ˉa?·-?1?鉔¨?è?ˉ·(ˉ¥?1“éa?èˉ?‰‰?·-é-¨è?ˉ°?μo0)

¨·o?-°è?ˉ?”¨é·¤§·?5°6a°éo§ˉ¤§é?¨?o?è?ˉ?”¨éè′oé¨10^3103¥”?è?3a·-¤§é?¨?o?è?ˉ?”¨éé?è?…è10^2102

è1‰?è?èˉé°?μ–1?31‘3°?μ?ˉ1?¤§?°?·ˉ?”±è?¨°ˉ¥—¥é°è–1?3¨·ˉ?ˉ”?°è–1?3?è|é?èˉ¥?±-o–?o?ˉ1?ˉ”ˉ¥—¥

‘1ˉ¥?…§”?èo2024?1′?o|?ˉè§–“è?o?¤§°

temp_l=data2024_states[data2024_states.LOW_ESTIMATE!=-1].copy()temp_l.loc[:,'Estimate_method']='LOW_ESTIMATE'temp_l.loc[:,'estimate']=temp_l.LOW_ESTIMATEtemp_h=data2024_statestemp_h.loc[:,'Estimate_method']='HIGH_ESTIMATE'temp_h.loc[:,'estimate']=temp_l.HIGH_ESTIMATEtemp=pd.concat([temp_l,temp_h],axis=0).sort_values('STATE')plt.figure(figsize=(30,8))sns.boxplot(x="STATE",y="estimate",hue='Estimate_method',data=temp)plt.yscale('log')plt.xlabel("State")plt.ylabel("Usagepesticide-use")plt.title("Pesticide-useinallstatesinyear2024")plt.grid()

–è¤?-?oμ?èˉ1°–?±è?饓è?ˉ”¨é¨·?·?–é?£?1‘?ˉ¥¨?¤oè-¥?ˉ1?o”o¤a?1′?o|·è?ˉ?13”¨é?

states2024mean=data2024_states[data2024_states.LOW_ESTIMATE!=-1][['STATE','LOW_ESTIMATE','HIGH_ESTIMATE']].groupby('STATE').mean()states2024mean=data2024_states[data2024_states.LOW_ESTIMATE!=-1][['STATE','LOW_ESTIMATE','HIGH_ESTIMATE']].groupby('STATE').mean()states2024mean.plot(kind='bar',grid=True,figsize=(20,5))plt.xticks(rotation=0)plt.title("Meanvalueofpesticide-useofallstatesinyear2024")states2024mean.plot(kind='bar',grid=True,figsize=(20,5))plt.xticks(rotation=0)plt.title("Meanvalueofpesticide-useofallstatesinyear2024")

è?¥èè?‘¤a?1′1?é—′¨·?”¨”¨é–?ˉ¥′°—?é—′?‰1ˉ|¥·?……?“°o¥

(states2024mean-states2024mean).fillna(0).plot(kind='bar',grid=True,figsize=(20,5))plt.xticks(rotation=0)plt.title("TheDifferences(changes)inallStatesbetweenyear2024andyear2024")plt.show()

?è?°2024?1′°2024?1′·è?ˉ?13”¨é¨¤?§°?μ–1?3–…μ?…-?”±?o2‰CA?·¨2024?1′?°‰¥?-?1a…–…μ—ˉ?¤?§°?μ?é¨a·?–?·?o°?o°?줧?o?é°?μ°è±?

°?-¤è?°?ˉè§–èè?è¤?è‘è?3o·-o?è?ˉ”¨?ˉè¢′¥‰?o?1”‘è2‰èè?‘ˉ?“a?oè?ˉ¨?…-?o§?”±?“¥?¤a?1′?è?ˉ”¨–?·

‘°ˉ?”°é?¢?oè°¥?¥ˉ¢è?¨ˉ?“a?oè?ˉˉoo?°‘±?”¨¥1′é?è?ˉ”¨…μ

num=10startangle=90#LOW_ESTIMATEcompound2024sum=data2024_states[data2024_states.LOW_ESTIMATE!=-1].groupby(['COMPOUND']).sum()compound2024sum=data2024_states[data2024_states.LOW_ESTIMATE!=-1].groupby(['COMPOUND']).sum()labels2024=compound2024sum.LOW_ESTIMATE.sort_values(ascending=False).head(num).index.append(pd.Index(['Others']))fracs2024=compound2024sum.LOW_ESTIMATE.sort_values(ascending=False).head(num)fracs2024=fracs2024.append(pd.Series(compound2024sum.LOW_ESTIMATE.sort_values(ascending=False).tail(-num).sum()))labels2024=compound2024sum.LOW_ESTIMATE.sort_values(ascending=False).head(num).index.append(pd.Index(['Others']))fracs2024=compound2024sum.LOW_ESTIMATE.sort_values(ascending=False).head(num)fracs2024=fracs2024.append(pd.Series(compound2024sum.LOW_ESTIMATE.sort_values(ascending=False).tail(-num).sum()))explode=(0.05,)+(0,)*(num)color=sns.color_palette("Paired")plt.figure(1,figsize=(12,12))plt.subplot(2,2,1)plt.pie(fracs2024,explode=explode,labels=labels2024,autopct='%1.1f%%',shadow=True,startangle=startangle,colors=color)plt.title('Compoundinallstatesinyear2024',bbox={'facecolor':'0.8','pad':5})plt.ylabel('LOW_ESTIMATE')plt.subplot(2,2,2)plt.pie(fracs2024,explode=explode,labels=labels2024,autopct='%1.1f%%',shadow=True,startangle=startangle,colors=color)plt.title('Compoundinallstatesinyear2024',bbox={'facecolor':'0.8','pad':5})#HIGH_ESTIMATEcompound2024sum=data2024_states[data2024_states.LOW_ESTIMATE!=-1].groupby(['COMPOUND']).sum()compound2024sum=data2024_states[data2024_states.LOW_ESTIMATE!=-1].groupby(['COMPOUND']).sum()labels2024=compound2024sum.HIGH_ESTIMATE.sort_values(ascending=False).head(num).index.append(pd.Index(['Others']))fracs2024=compound2024sum.HIGH_ESTIMATE.sort_values(ascending=False).head(num)fracs2024=fracs2024.append(pd.Series(compound2024sum.LOW_ESTIMATE.sort_values(ascending=False).tail(-num).sum()))labels2024=compound2024sum.HIGH_ESTIMATE.sort_values(ascending=False).head(num).index.append(pd.Index(['Others']))fracs2024=compound2024sum.HIGH_ESTIMATE.sort_values(ascending=False).head(num)fracs2024=fracs2024.append(pd.Series(compound2024sum.HIGH_ESTIMATE.sort_values(ascending=False).tail(-num).sum()))plt.subplot(2,2,3)plt.pie(fracs2024,explode=explode,labels=labels2024,autopct='%1.1f%%',shadow=True,startangle=startangle,colors=color)plt.ylabel('HIGH_ESTIMATE')plt.subplot(2,2,4)plt.pie(fracs2024,explode=explode,labels=labels2024,autopct='%1.1f%%',shadow=True,startangle=startangle,colors=color)plt.show()

?è?°2024?1′°2024?1′?¨·13”¨?–?¤§‰?25?§è?ˉ¨¤?§°?μ–1?3–…μ?1¤–?‘°SulfuricAcidè?ˉ-?o|¨?–°2024?1′?o|-?é?è1°±é—′¥°è§£éo¨2024?1′?o|-?o?1?Glyphosateè?ˉ—¢ˉ?”¨é¤§1ˉ¨·-é?2024?1′·?13”¨éo°2024?1′?o|‰

¥?¥?‘§?éèè?‘°‰1?—?oè?°?ˉè§–……ˉ?ˉ1°ˉ·‰èèo——?’?oè?°?è‰oo|?-‰ééè|‘°…–?o¥1?è-¥è§ˉ?§è?ˉ…?1′?o|è?ˉ”¨°?μ?é°…μ

‘§?”¨geopandas?’?contextily…¥′?–1¤?’–°?oé—′°‰è£…èˉ|…èˉ·…§?‘è?¥o°è…¥…importgeopandas¥é”ˉèISSUEè§£3é—?颉°o°èé?è?USCensus–github

geopandas/rasterio/mapclassify/descartes‰è£…3

condainstallgeopandas

condainstallrasterio

condainstallmapclassify

condainstalldescartes

importgeopandasasgpus_geod=gp.GeoDataFrame.from_file('./cb_2024_us_county_500k/cb_2024_us_county_500k.shp',encoding='UTF-8')us_geod['COUNTY_CODE']=us_geod.COUNTYFP.map(lambdax:int(x))us_geod['STATE_CODE']=us_geod.STATEFP.map(lambdax:int(x))#Checkprint([codeforcodeindata2024_states.COUNTY_CODE.unique()ifcodenotinus_geod.COUNTYFP.map(lambdax:int(x))])print([codeforcodeindata2024_states.STATE_CODE.unique()ifcodenotinus_geod.STATEFP.map(lambdax:int(x))])print([codeforcodeindata2024_states.COUNTY_CODE.unique()ifcodenotinus_geod.COUNTYFP.map(lambdax:int(x))])print([codeforcodeindata2024_states.STATE_CODE.unique()ifcodenotinus_geod.STATEFP.map(lambdax:int(x))])data2024_geod=gp.GeoDataFrame(data2024_states)#è¢data2024_merge=gp.GeoDataFrame.merge(data2024_geod,us_geod,on=['COUNTY_CODE','STATE_CODE'],how='left')#1?data2024_geod=gp.GeoDataFrame(data2024_states)#è¢data2024_merge=gp.GeoDataFrame.merge(data2024_geod,us_geod,on=['COUNTY_CODE','STATE_CODE'],how='left')#1?print(sum(np.isnan(data2024_merge['HIGH_ESTIMATE'])))print(sum(np.isnan(data2024_merge['HIGH_ESTIMATE'])))data2024_merge.head()

‘°è·°?°’¤a?1′?o|è?ˉ”¨°èèo?1?1”o‰è?ˉ°?·éˉ‰?ˉ1?o”o°ˉ—?èè?‘?oa?¥è?ˉ”¨…μ·?’?éa?èˉo°1-£§

é|–?…‘…?o2024-2024?1′è?ˉ”¨éé°?μ¨·

#importcontextilyasctximportrasterioasriortr=rio.open('america_6.tif')defadd_basemap(ax,rtr):#NOTEthetransposeoftheimagedataimg=np.array([bandforbandinrtr.read()]).transpose(1,2,0)bb=rtr.boundsxmin,xmax,ymin,ymax=(bb.left,bb.right,bb.bottom,bb.top)#ax.axis()ax.imshow(img,extent=(xmin,xmax,ymin,ymax))ax.axis((xmin,xmax,ymin,ymax))ax.set_axis_off()reported2024_sum=gp.GeoDataFrame(pd.merge(data2024_merge.groupby(['STATE_CODE','COUNTY_CODE']).sum().reset_index(),us_geod[['STATE_CODE','COUNTY_CODE','geometry']],on=['STATE_CODE','COUNTY_CODE'],how='left'))reported2024_sum.crs={'init':'epsg:4326'}reported2024_sum=gp.GeoDataFrame(pd.merge(data2024_merge.groupby(['STATE_CODE','COUNTY_CODE']).sum().reset_index(),us_geod[['STATE_CODE','COUNTY_CODE','geometry']],on=['STATE_CODE','COUNTY_CODE'],how='left'))reported2024_sum.crs={'init':'epsg:4326'}fig,ax1=plt.subplots(1,figsize=(20,20))add_basemap(ax1,rtr)reported2024_sum.to_crs(rtr.crs).plot('HIGH_ESTIMATE',scheme='Quantiles',k=300,cmap='OrRd',ax=ax1,alpha=0.5,edgecolor='k')ax1.set_title('Usagepesticide-use(Highestimate),US,2024',fontsize=15)#è¢é¢?plt.show()fig,ax2=plt.subplots(1,figsize=(20,20))add_basemap(ax2,rtr)reported2024_sum.to_crs(rtr.crs).plot('HIGH_ESTIMATE',scheme='Quantiles',k=300,cmap='OrRd',ax=ax2,alpha=0.5,edgecolor='k')ax2.set_title('Usagepesticide-use(Highestimate),US,2024',fontsize=15)#è¢é¢?plt.show()

-è?ˉé¨?o?°“è?¨°‘?ˉ¥°°oè?ˉ”¨é‰o?–?‰11è?”éèˉ1?ˉ”°¢‘?ˉ¥‘°¨é¤§é”¨è?ˉ?°o?oˉ1?o”?o23?μ22’13?°|?-‰è1“?§¤?‰°o

‘è|?èˉ¤a?1′éoˉ1?“a?§è?ˉ”¨é¤§é°—é‰

#importcontextilyasctximportrasterioasriortr=rio.open('america_6.tif')defadd_basemap(ax,rtr):#NOTEthetransposeoftheimagedataimg=np.array([bandforbandinrtr.read()]).transpose(1,2,0)bb=rtr.boundsxmin,xmax,ymin,ymax=(bb.left,bb.right,bb.bottom,bb.top)#ax.axis()ax.imshow(img,extent=(xmin,xmax,ymin,ymax))ax.axis((xmin,xmax,ymin,ymax))ax.set_axis_off()table=data2024_merge.groupby(['STATE_CODE','COUNTY_CODE','COMPOUND'])['HIGH_ESTIMATE'].mean()table=table.unstack('COMPOUND').reset_index().fillna(0)table['compound']=[table.columns[index]forindexintable.values.argmax(axis=1)]reported2024_com=gp.GeoDataFrame(pd.merge(table[['STATE_CODE','COUNTY_CODE','compound']],us_geod[['STATE_CODE','COUNTY_CODE','geometry']],on=['STATE_CODE','COUNTY_CODE'],how='left'))reported2024_com['compound_simple']=reported2024_com['compound'].replace(reported2024_com['compound'].value_counts().tail(-16).index,'Others')reported2024_com.crs={'init':'epsg:4326'}table=data2024_merge.groupby(['STATE_CODE','COUNTY_CODE','COMPOUND'])['HIGH_ESTIMATE'].mean()table=table.unstack('COMPOUND').reset_index().fillna(0)table['compound']=[table.columns[index]forindexintable.values.argmax(axis=1)]reported2024_com=gp.GeoDataFrame(pd.merge(table[['STATE_CODE','COUNTY_CODE','compound']],us_geod[['STATE_CODE','COUNTY_CODE','geometry']],on=['STATE_CODE','COUNTY_CODE'],how='left'))reported2024_com['compound_simple']=reported2024_com['compound'].replace(reported2024_com['compound'].value_counts().tail(-16).index,'Others')reported2024_com.crs={'init':'epsg:4326'}fig,ax1=plt.subplots(1,figsize=(20,20))add_basemap(ax1,rtr)reported2024_com.to_crs(rtr.crs).plot('compound_simple',categorical=True,ax=ax1,cmap='prism',alpha=0.4,edgecolor='k',legend=True)ax1.set_title('Mostusagepesticide-useofcompound(Highestimate),US,2024',fontsize=15)#è¢é¢?plt.show()fig,ax2=plt.subplots(1,figsize=(20,20))add_basemap(ax2,rtr)reported2024_com.to_crs(rtr.crs).plot('compound_simple',categorical=True,ax=ax2,cmap='prism',alpha=0.4,edgecolor='k',legend=True)ax2.set_title('Mostusagepesticide-useofcompound(Highestimate),US,2024',fontsize=15)#è¢é¢?plt.show()

é?¢¤?ˉ¥—¥è?ˉ”¨é1‘°°?o?–‰11?ˉèˉ?”±?o?éè?‘?°o?°”ˉ?¢?駤?±‰-‰-¤?¤–è?ˉGlyphosate?…ˉ2024?1′?’?2024?1′”¨é¤§è?ˉé…–1è?”°¨-é?¨?1¤§°o?’é?¨é?¨?°oé£?é·2?1…

?°“

éè-|?1ˉ¥”¨Python±‰±o“?ˉ1°é‰èè?’“°¤o?ˉ1°é¢?′¢§o§?”?¤§?ˉ‘?-¤?¤–·±?…¥¥è§|?o°éo§è?’?éo§ˉè§–?“°¤?…ˉ?ˉ1°ˉ?ˉè§–o?èˉ¤è′μè·ˉ?’′