Dear Harrison, I use python for data analytics and machine learning. I find it challenging to organise my code when the code base grows bigger. In fact, I don't have a good way to organise my code at all. Lately, I have been thinking to learn OOP for data analytics. However, I couldn't find any good resources online with practical examples, such as use OOP to import data, clean data, analyse data and model data and then plot the output. Could you please give me some tips with examples how to organise my code, how to code like a real coder? Also if you think OOP is a good option, could you please give me some examples in terms of how to apply it in data analysis?
Thank you so much! Rachel
You must be logged in to post. Please login or register an account.
OOP could be useful to you, but OOP != cleanliness of code.
You can easily keep things clean with functions, you just need to work on it. OOP is really more for architecting something to be interacted with.
You could check out the OOP tutorials of the fundamentals, starting here: https://pythonprogramming.net/object-oriented-programming-introduction-intermediate-python-tutorial/
Otherwise, generally, if you're winding up with a bunch of code, it's best to start putting those functions in separate files. For example, if you have a bunch of functions that do data visualization, it can be wise to create a new file called visuals.py, and put your graphing functions in there.
Then, in some sort of main.py file or something along those lines, you just simply import those functions from visuals. For example, if you have a function in visuals called plot_a_line, you can do something like
from visuals import plot_a_line
plot_a_line(x,y)
...etc. You also don't want too many side python files that you're importing, but that can be a great first step for cleaning up a messy single script.
-Harrison 8 years ago
You must be logged in to post. Please login or register an account.
Thank you very much! Your tips have been very helpful! :)
-rachelhuang 8 years ago
You must be logged in to post. Please login or register an account.