农药使用量数据(农药污染数据)
°?–è?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)
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?-°è?ˉ?”¨é·¤§·?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")
(states2024mean-states2024mean).fillna(0).plot(kind='bar',grid=True,figsize=(20,5))plt.xticks(rotation=0)plt.title("TheDifferences(changes)inallStatesbetweenyear2024andyear2024")plt.show()
°?-¤è?°?ˉè§–èè?è¤?è‘è?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()
¥?¥?‘§?éèè?‘°‰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()
é|–?…‘…?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()
‘è|?èˉ¤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ˉ¥”¨Python±‰±o“?ˉ1°é‰èè?’“°¤o?ˉ1°é¢?′¢§o§?”?¤§?ˉ‘?-¤?¤–·±?…¥¥è§|?o°éo§è?’?éo§ˉè§–?“°¤?…ˉ?ˉ1°ˉ?ˉè§–o?èˉ¤è′μè·ˉ?’′
热门作者: 农业播报侠 种子小百科 农产新干线 农情领航灯 绿色农业防治通 种子故事