Issue
I have the following columns in a data-frame df:
columns = ['temperature','humidity' ,'pressure','rain' ,'lightavgw/o0' ,'lightmax','moisture']
What I want is to create a loop where I can plot the boxplot of all the columns through a single loop. I tried the following code:
columns = ['temperature','humidity' ,'pressure','rain' ,'lightavgw/o0' ,'lightmax','moisture']
for col in columns:
plt.boxplot(df[col])
But its plotting it in the same boxplot.
Solution
You can directly plot the data frame instead of going through the loop
Example code:
import numpy as np;
import pandas as pd
import matplotlib.pyplot as plt
data = np.random.random(size=(4,4))
df = pd.DataFrame(data, columns = ['A','B','C','D'])
df.boxplot()
plt.show()
Output:
Answered By - Siva Shanmugam
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.