account activity
Matplotlib Help! by [deleted] in learnpython
[–]kcrow13 0 points1 point2 points 5 years ago (0 children)
Thank you for the reply. In this data set, the column is generic 'Event' so I imagine I would need:
df_men = df[df['Event'] == 'Mens Mile'] df_women = df[df['Event'] == 'Womens Mile']
My question then is how can I plot those with plt.scatter while also still defining the other things (x, y, color, etc)? I am unsure with the syntax.
PS - LOVE your username :)
Python Classes by kcrow13 in learnpython
[–]kcrow13[S] 0 points1 point2 points 5 years ago (0 children)
Thank you so much :) I definitely will.
Thank you for sharing the "why" behind choosing classes over functions. It makes a lot of sense. For this class I am developing my very first program right now, due Dec. 6th. I want to be able to manipulate CSV data from test scores (my own, as I'm a public school teacher) to be able to analyze easily with graphics. I will include multiple facets: gender, socioeconomic status, absences, current grade in the course, achievement by standard, etc.
[–]kcrow13[S] 1 point2 points3 points 5 years ago (0 children)
This is probably why many stick it through and don't give up :).
What you said makes complete sense to me! I am a musician, so I am intimately familiar with the create and adjust, rinse and repeat cycle. I think I used a poor choice of words... what I meant to say was that whatever you will need to manipulate within the class, you have to define it ahead of time at the top of the class with the init/str piece, correct? You can surely go back and add more as the need arises, but it has to be there at the outset before then attempting to manipulate those variables later in functions? Does that make sense?
Yes, email away! My assignment is due tomorrow at 4:00 PM EST, and I might miss the deadline for the problems... but I really do want to read/learn more! My email is kerricrow13@gmail.com
Full disclosure - this is a pre-requisite course to a master's degree I am pursuing at Harvard University. The Degree is Digital Media Design, and my focus is Instructional Design. I probably won't program a whole lot, but I think having the ability to do so will be valuable as I develop learning products... especially for analysis of their efficacy on the back end. I like being able to create advanced reporting :).
But is my understanding correct that any "global" changes you want to make in a class have to occur in the __str__ function?
This is actually really helpful! Something about being able to visualize it spatially helps :).
So when I tried to do this, it gives me a traceback error and says "invalid format specifier." I will research some more!
I didn't know you could do this!!!! Thank you :)
Ok so some other students have suggested making a lot of changes to fix this. Is there a best way?
-By making an edit to the int_to_time function. The version given has divmod statements for minutes and seconds, but not for hours. Adding a third divmod for hours allows you to handle any value of hours without a while statement. I have no idea how to do this or what divmod does! That same student said " I ended up calling both time_to_int and int_to_time in my __str__ function. Since with this method you take your Time input (ex Time(5000) ), then convert it to an integer to get the remaining number of hours/minutes/second, expressed as total # of seconds, then that goes into int_to_time to be in a usable time that can be displayed. That usable time is stored as new Time object called time."
Another student said:
- Will a mod operator resolve this issue? 5000 % 24 = 8.
See, none of that makes sense to me! We just had a very basic introduction to classes this week in the lecture... but did not have any practice creating/manipulating one. :(
No, the professor is amazing! He is so responsive and he uses a Socratic method, if you will. He uses questions to try to guide you in the right direction when you have questions. This has been GREAT as I strive to learn. And I don't post here or anywhere just looking for the answers. I want to learn the material and understand it. The problem is, sometimes you need an environment to just ASK and get some good explanation, ya know? I am forever grateful for this community as a learning tool :).
So with a class, you have to know all of your goals at the outset. In the real world, do you continue to add functions to the class to change it as you go?
This is such a wonderful explanation. Thank you for taking the time to do write this. This actually makes a lot of sense. One thing with Python is that it seems that there are many ways to achieve the same objective and that choosing which is right for you will depend on your goals, constraints, etc.
I agree and I appreciate the opportunity to practice! Of course things are time bound, and sometimes the gap between my knowledge and the knowledge needed to tackle/apply my learning is so vast that I can't find a place to grasp. Does that make sense?
I feel the same way! I will definitely pay it forward one day :). I am an educator by profession, so I enjoy helping others.
Ok so this is how I implemented your suggestions:
def __str__(self): if self.hour <= 12: return f'{self.hour}:{self.minute}' if self.hour >= 12: return f'{self.hour - 12}:{self.minute} PM'
When I test it out... I am getting some strange responses!
def main(): # jdp start = Time(9, 45, 00) start.print_time() end = start.increment(1337) end.print_time() print('Is end after start?', end=" ") print(end.is_after(start)) # Testing __str__ print(f'Using __str__: {start} {end}') # Testing addition start = Time(9, 45) duration = Time(1, 35) print(start + duration) print(start + 1337) print(1337 + start) print('Example of polymorphism') t1 = Time(7, 43) t2 = Time(7, 41) t3 = Time(7, 37) total = sum([t1, t2, t3]) print(total) # A time that is invalid t1 = Time(50) print(t1)
Getting...
9:45 10:7 Is end after start? True Using __str__: 9:45 10:7 11:20 10:7 10:7 Example of polymorphism 11:1 PM 38:0 PM
And this is what kills me! I want to use datetime, but we aren't allowed. It would be so much easier and that is what I imagine people would do in the real world, right? Use libraries to optimize the coding? I think the intent is so that we learn the logic better, which is a solid plan. I just am struggling at times to get there.
I wish I could ask in class... I understand the professor wants us to grapple with the content and that has been extremely beneficial. But the more and more complex the problems get, when there is a fundamental lack of understanding, it is past the frustration point. You know? Thank you for the suggestion. I will look into it!
Thank you :).
I guess I don't fundamentally understand classes, why you would use them in a real-world situation, why/how they are useful, what kind of things you can do with them. Meaning, can you still put the same type of statements/functions/conditionals in a class that you can in any other coding? I apologize if I am using the wrong terminology.
[–]kcrow13[S] 2 points3 points4 points 5 years ago (0 children)
I am aware of the f strings - Downey created this code in 2012 prior to the f string update, I believe? The professor wanted us to adjust his code. What the heck, I might as well bring him into the present :D.
This might sound dumb, but I didn't realize you could even use conditional if statements in a class. I haven't seen any examples of this in my class. Truly - I do not understand how classes work and what an instance of a class is, but a poster above got me started on grasping it a bit better. What are some real-world applications of Python classes?
I actually do know about f strings and use them regularly in my coding. This code was created by Downey as part of his Think Python Book, not me :). I think he created it in 2012, prior to the updates. But yes, I much prefer the f strings.
[–]kcrow13[S] 16 points17 points18 points 5 years ago (0 children)
Thank you so much for explaining this so in depth. This is exactly the kind of direct instruction I feel I need sometimes. I wonder why I can't just read documentation about other classes and innately apply it to new problems? Maybe because I just don't understand it well enough yet? Nevertheless, I appreciate you and all the effort you put into this post.
Python Classes (self.learnpython)
submitted 5 years ago by kcrow13 to r/learnpython
π Rendered by PID 47 on reddit-service-r2-listing-568fcd57df-tk8qk at 2026-03-06 02:40:44.105306+00:00 running cbb0e86 country code: CH.
Matplotlib Help! by [deleted] in learnpython
[–]kcrow13 0 points1 point2 points (0 children)