Python Forum
For Loop: To see plot for different columns
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
For Loop: To see plot for different columns
#1
Hi


Currently, I ran the below code in Spyder. And I only see the last plot (Age) in my "Plots" window. How can I see the plot for each column as the code loops through the columns?

Thank you


import pandas as pd 
import seaborn as sns

df=pd.DataFrame ({'Sex': ['M', 'M', 'F'],
                  'Age': ['19', '88','14'] 
                  })

for col in df.columns:
    c=df.groupby(col)[col].count()

    sns.barplot(x=c.index,y=c.values)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to loop through code to plot seaborn line plots across multiple subplots eyavuz21 0 1,696 Dec-05-2022, 10:46 AM
Last Post: eyavuz21
  Nested for loops: Iterating over columns of a DataFrame to plot on subplots dm222 0 1,727 Aug-19-2022, 11:07 AM
Last Post: dm222
  How to plot intraday data of several days in one plot mistermister 3 2,933 Dec-15-2020, 07:43 PM
Last Post: deanhystad
  how to nest loop for 4*4 scatter plot kassamohammed 0 2,582 Jun-23-2020, 09:47 AM
Last Post: kassamohammed
  How to plot vertically stacked plot with same x-axis and SriMekala 0 1,944 Jun-12-2019, 03:31 PM
Last Post: SriMekala
  Loop files - Extract List Data To Individual Columns in CSV dj99 5 3,297 May-19-2019, 10:29 AM
Last Post: dj99

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020