Use a loop to plot n charts Python

前端 未结 4 428
盖世英雄少女心
盖世英雄少女心 2020-12-02 09:25

I have a set of data that I load into python using a pandas dataframe. What I would like to do is create a loop that will print a plot for all the elements in their own fram

4条回答
  •  生来不讨喜
    2020-12-02 09:51

    We can create a for loop and pass all the numeric columns into it. The loop will plot the graphs one by one in separate pane as we are including plt.figure() into it.

    import pandas as pd
    import seaborn as sns
    import numpy as np
    
    numeric_features=[x for x in data.columns if data[x].dtype!="object"]
    #taking only the numeric columns from the dataframe.
    
    for i in data[numeric_features].columns:
        plt.figure(figsize=(12,5))
        plt.title(i)
        sns.boxplot(data=data[i])
    

提交回复
热议问题