Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

pandas - How to plot values of my columns being above a certain treshold?

I've been stuck with this problem for a while. I have a dataset which looks more or less like this:

Students     Subject       Mark
1            M F           7 4 3 7
2            I             5 6 
3            M F I S       2 3 0 
4            M             2 2 
5            F M I         5 1
6            I M F         6 2 3
7            I M           7

Now, I want to create a barplot using pandas and seaborn showing how many students:

  • Have 3 ore more letters in the column "Subject"
  • Have at least one 3 in the colum "Marks"
  • Have both things

I tried with:

n_subject = dataset['Subject'].str.count('w+')
dataset['NumberSubjects']= n_subject
n_over = dataset[dataset.n_subject >= 3.0]

But it does not work and I'm stuck. I'm sure it is a very basic problem but I don't know what to do.

question from:https://stackoverflow.com/questions/65836010/how-to-plot-values-of-my-columns-being-above-a-certain-treshold

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

3 or more subjects:

df["Subject"].str.count("w+") >= 3

Has one or more marks of 3:

df["Mark"].str.count("3") >= 1

Both:

(df["Subject"].str.count("w+") >= 3) & (df["Mark"].str.count("3") >= 1)

Boolean representation:

   Students  Subject     Mark    one    two  three
0         1      M F  7 4 3 7  False   True  False
1         2        I      5 6  False  False  False
2         3  M F I S    2 3 0   True   True   True
3         4        M      2 2  False  False  False
4         5    F M I      5 1   True  False  False
5         6    I M F    6 2 3   True   True   True
6         7      I M        7  False  False  False

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...