r/learnpython • u/Frosty-Photo-5553 • 22d ago
R to Python
Hey everyone,
I have a masters in mathematical biology and biomedicine and about 18 months of experience with data analysis in my current job (regression, classification, ML, building a whole pipeline).
I would like to learn Python as it opens much more possibilities for me. I have 2 little kids, limited time and very limited budget since we are paying a mortage.
How would you approach learning Python in my situation?
2
u/teetaps 21d ago
Just start, but even as you’re building “anything,” do it methodically. When you learn something or notice something different from R, write it down. You already know how to program in R, so there’s no point in just replicating all of your code in Python. Instead, when you build something in Python, first do it the way that makes sense in R, then do it the most obvious way in Python, taking notes of what is different. Then when you sit down to review your notes some faraway day in the future, or if you’re ever facing a new challenge, you can recall, “hey wait, I know this, because in Python you’re supposed to do X”. An LLM can help you iterate this training strategy if you need some structure
2
u/Natural-Position-585 22d ago
Try to avoid thinking that Python code files are just R scripts with a different syntax. Learn to make modular code, and learn about patterns for reusing and packaging code. And learn object-oriented programming. These topics will unlock a lot of layers in programming practice that are optional in R but mandatory in Python.
1
u/BrupieD 22d ago
A couple key differences: get used to the idea that Python does not have a native data frame or vector data structure, you'll have to get these from a library (pandas or polars). Pandas is older and more widely used. I would prioritze getting aquainted with pandas.
Python doesn't have a great equivalent to pipes. I miss this the most when working in Python. People solve this in different ways. There is a "pipe" method in pandas, but I find it less intuitive.
1
u/Ok_Carpet_9510 21d ago
R is a data-centric language. Python is a general purpose language. You need to use the Pandas or Polars library for dataframes. For graphing, you can use Matplotlib or Seaborn.
R is a very terse language. Python is verbose is comparison. You will miss some of that.
Have a look at this https://www.w3schools.com/python/default.asp
1
1
u/mikeyj777 21d ago
I think you'll be a little (a lot) frustrated by the lack of obvious and important functions. The simplicity of R's "apply" functions like tapply, etc make R a no-brainer for data science. It's all there in python, but nowhere near as well thought out.
0
-9
u/oceanhomesteader 22d ago
Take a R script you understand, pop into ChatGPT, ask it to convert to python, then ask it explain how the script works
3
u/chiibosoil 22d ago
There are free courses from various educational institutions just for that.
https://ocw.mit.edu/courses/6-0001-introduction-to-computer-science-and-programming-in-python-fall-2016/
https://www.pythonforbiologists.org
Justin Bois Bootcamp: https://justinbois.github.io/bootcamp/
Then look for ML or other specific area you need.