You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
KeyErrorTraceback (mostrecentcalllast)
File~\anaconda3\lib\site-packages\pandas\core\indexes\base.py:3802, inIndex.get_loc(self, key, method, tolerance)
3801try:
->3802returnself._engine.get_loc(casted_key)
3803exceptKeyErroraserr:
File~\anaconda3\lib\site-packages\pandas\_libs\index.pyx:138, inpandas._libs.index.IndexEngine.get_loc()
File~\anaconda3\lib\site-packages\pandas\_libs\index.pyx:165, inpandas._libs.index.IndexEngine.get_loc()
Filepandas\_libs\hashtable_class_helper.pxi:5745, inpandas._libs.hashtable.PyObjectHashTable.get_item()
Filepandas\_libs\hashtable_class_helper.pxi:5753, inpandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'so2'Theaboveexceptionwasthedirectcauseofthefollowingexception:
KeyErrorTraceback (mostrecentcalllast)
CellIn[4], line1512#benzene.dropna(inplace=True)13benzene.fillna(0, inplace=True)
--->15summaryPlot(benzene)
File~\anaconda3\lib\site-packages\vayu\summaryPlot.py:126, insummaryPlot(df)
124plt.subplot(9, 3, sub)
125sub=sub+1-->126a=df_all[dataPoints[i]].plot.line(color="gold")
127a.axes.get_xaxis().set_visible(False)
128a.yaxis.set_label_position("left")
File~\anaconda3\lib\site-packages\pandas\core\frame.py:3807, inDataFrame.__getitem__(self, key)
3805ifself.columns.nlevels>1:
3806returnself._getitem_multilevel(key)
->3807indexer=self.columns.get_loc(key)
3808ifis_integer(indexer):
3809indexer= [indexer]
File~\anaconda3\lib\site-packages\pandas\core\indexes\base.py:3804, inIndex.get_loc(self, key, method, tolerance)
3802returnself._engine.get_loc(casted_key)
3803exceptKeyErroraserr:
->3804raiseKeyError(key) fromerr3805exceptTypeError:
3806# If we have a listlike key, _check_indexing_error will raise3807# InvalidIndexError. Otherwise we fall through and re-raise3808# the TypeError.3809self._check_indexing_error(key)
KeyError: 'so2'
OUTPUT:
Explaintion:
Here, the code expects so2 attribute to be present in the the dataframe which is not everytime possible, there can be possibilities that so2 or someother attribute is not present in the dataframe, even if its not present the code should run smoothly without any error.
This line creates a list called dataPoints containing strings representing different data points or columns in the DataFrame. Each string corresponds to a specific column name in the DataFrame.
This line initiates a loop that iterates over each column name in the df_all DataFrame. The loop assigns each column name to the variable column in each iteration.
This line selects a specific column from the DataFrame df_all using the index i from the dataPoints list.
and as we are making a loop from datapoints it expects all the pollutants which are specified in datapoints should be present in dataframe, which is giving error if any of the pollutant is not present in user's dataframe.
Scalability: If we need to work with additional pollutants or categories in the future, we would need to manually add new variables to the code. This can be cumbersome and error-prone, especially as the number of pollutants and categories increases.
Solution:
Using a list can help decrease the amount of code and repetitiveness.
The above site states that: Details of air quality index along with range of concentrations of criteria pollutant PM2.5, PM10, NOX, SOX, O3, CO, Pb and NH3.
which means the above polutants contributes for AQI.
Hence added Pb, NH3 into the code which wasn't present before and removed wd and ws which doesn't contribute for AQI.
@nipunbatra , @patel-zeel
Description:
I went through the whole source code of SummaryPlot where I feel that the code can be optimized for better performance.
Code:
Error:
OUTPUT:
Explaintion:
Here, the code expects
so2
attribute to be present in the the dataframe which is not everytime possible, there can be possibilities that so2 or someother attribute is not present in the dataframe, even if its not present the code should run smoothly without any error.ISSUE-1: Making the function general
Source Code:
vayu/vayu/summaryPlot.py
Line 51 in ef99aef
This line assigns the value of the variable df to a new variable
df_all
. It creates a new reference to the same DataFrame object.vayu/vayu/summaryPlot.py
Line 54 in ef99aef
This line creates a list called
dataPoints
containing strings representing different data points or columns in the DataFrame. Each string corresponds to a specific column name in the DataFrame.vayu/vayu/summaryPlot.py
Line 56 in ef99aef
This line initiates a loop that iterates over each column name in the
df_all
DataFrame. The loop assigns each column name to the variable column in each iteration.vayu/vayu/summaryPlot.py
Line 126 in ef99aef
This line selects a specific column from the DataFrame
df_all
using the indexi
from thedataPoints
list.and as we are making a loop from
datapoints
it expects all thepollutants
which are specified indatapoints
should be present in dataframe, which is giving error if any of the pollutant is not present in user's dataframe.hence this line should be written as follows:
Solution:
The above line will take only the columns which are present in the user's dataframe and will plot that only without giving the error.
ISSUE-2: Code Opimization
vayu/vayu/summaryPlot.py
Lines 22 to 39 in ef99aef
Scalability: If we need to work with additional pollutants or categories in the future, we would need to manually add new variables to the code. This can be cumbersome and error-prone, especially as the number of pollutants and categories increases.
Solution:
Using a list can help decrease the amount of code and repetitiveness.
ISSUE-3: Adding other pollutants that contributes for generating AQI
https://www.ncbi.nlm.nih.gov/pmc/articles/PMC8137507/
The above site states that:
Details of air quality index along with range of concentrations of criteria pollutant PM2.5, PM10, NOX, SOX, O3, CO, Pb and NH3.
which means the above polutants contributes for AQI.
Hence added
Pb
,NH3
into the code which wasn't present before and removedwd
andws
which doesn't contribute for AQI.Now, this is how the whole code looks like:
Improved Code:
NOTE: I'm also adding
plt.savefig("summaryPlot.png", dpi=300, format="png")
to save the figure.OUTPUT:
The text was updated successfully, but these errors were encountered: