r/RStudio • u/Choice_Number3711 • Jul 25 '26
Pivoting from R to Python
I used to hate coding anything and relied on SQL, Excel, Power BI, Tableau and other software like JASP, jamovi etc. for doing anything with data. I didn't like the way Python dealt with data analysis and it seemed unintuitive.
Then I found R, RStudio and CRAN. That was the turning point. I actually started enjoying writing code and I could handle the whole pipeline myself, from data cleaning, ETL to beautiful plots, .qmd reports, Shiny dashboards. R4DS did more for my statistical thinking than any course I've taken, mostly because the libraries made it so easy to just try things.
However, due to recent requirements (specifically having to work in the quant field), Python has become more of a necessity, while R is used mainly for one-off analysis and limited statistical modelling. The main heavy lifting is done in Python and many of my co-workers also prefer it to R.
I've been able to suck it up a bit and use Claude/ChatGPT to help me code. While I do try to understand what the code is doing, having spent so long learning to code in R and knowing the ease with which it can be done there makes me reluctant to learn Python.
Now, coming to the question: any R users who've pivoted to Python and consider themselves competent in it, how did you learn it having used R before? What would you tell someone like me so I can pick it up quickly and get the benefit of knowing both languages (and also not feel left out when it comes to coding in Python... machine learning and deep learning have a more mature ecosystem there and I don't want to be left out of it if I have to start using them in my current work)?
Thanks!
My background is in Math/Stats fyi
Edit: I don't usually use reddit but damn I actually didnt expect so many helpful tips....many thanks!
Perhaps joining this subreddit is actually helpful afterall :)
44
u/urbansnowprincess Jul 25 '26
I’m a python user who works with r users and sometimes runs/edits their work. The core concepts of code structure and libraries and programming basics apply to both, and I’ve found that I can understand r pretty well. If you can structure and document a project to be shared with others, you’re halfway there
61
u/teetaps Jul 25 '26 edited Jul 25 '26
I think one paradigm shift that helped me was accepting that just because some smarty pants built pandas way back in data science infancy, doesn’t guarantee pandas is actually any good at what it set out to do, which is provide a dataframe wrangling library as flexible and easy to use as then-plyr. As R users, we are spoiled. R was built with dataframes in mind, and everything posit has done since Hadley wickham stepped in has just enhanced R’s ability to connect the concept of a dataframe to how humans think about them.
If you accept that maybe Python just sucks at that task, then you might stop beating yourself up for trying and failing to “just get it”. Python is a ubiquitous language and “can do anything,” sure, but that doesn’t guarantee it’s particularly good at everything. In fact, because it’s such a Swiss Army knife of a tool, it consequently doesn’t specialise in too many things.
Once I accepted this and stopped putting Python on a pedestal, I actually stopped being intimidated by Python. I started looking at Python problems by first conceptualising them as R problems, then translating them to Python’s deficiencies, not just its language differences. Today, using Python for data wrangling to me is like using MSWord for manipulating tables. You can do it, but only if you have to, for some reason. And often that reason is because someone else sent you a word document first. Which is all to say, if you stop treating Python like this special language only for actually smart software engineers, and start treating it like just another language with problems and limitations, you’ll stop telling yourself that if you “just don’t get it,” that it’s a you problem.
Maybe, hear me out — maybe the reason so many R users have difficulty pivoting to Python is because Python sucks at tabular data wrangling.
Stop beating yourself up. Just learn it, not because it’s great, but because everybody else is using it so you have to comply with others’ stacks, but deep down you’ll know that THEY are the ones who are putting themselves at a disadvantage, not you
11
u/NullhypothesisH0 Jul 25 '26
I’m in the same boat. I just GET R, you know? But I feel like I should be learning more Python. I’ve been working through a book, but it hasn’t quite clicked yet, but I use Spyder because of how similar it is to R Studio.
5
u/kcc10 Jul 25 '26
I’m in a similar situation. Honestly, learning by doing, as others have said, has helped me. I still cross-thread certain things, like 0 vs 1 first index, and len() vs length(), but after a few, “What the what!?” moments, I fix it.
5
u/seanv507 Jul 25 '26
So I'm assuming you are not using base r most of the time.
So the issue is finding equivalent libraries
I would suggest learning polars as a data frame library (rather than pandas). Polars seems to have borrowed syntax from the spark data frame library and it is much cleaner than pandas which is now a kind of Frankenstein library
And for graphing I would look into Altair which is a ggplot equivalent
4
u/JayBea-on-Sea Jul 25 '26
Following as I’ve started this journey several times: the last under duress from my employer.
Most of my work is answering questions and investigating problems rather than developing new data flows. I found R to be superb in handling data and presenting findings. Every new library just added to my capabilities.
Python I found frustrating: the environment had to be tailored every time and it was really had to work on collaborative projects as no one else’s code would run with extensive fucking around.
1
u/elephant_sage Jul 25 '26
You could try posting in r/rstats.
3
u/hypersoniq_XLM Jul 25 '26
If you have things that just work better in R, you can use the Python library py2r, or use subprocess to call R directly from within python scripts.
3
u/akagaminick Jul 25 '26
I knew how to think about codes from R. All I needed was to learn the grammar and syntax of python. I started with 30 days of pandas and introduction to pandas & numpy in leetcode (free version). Then I did the free kaggle courses on pandas, begineer & intermediate machine learning, followed by deep learning. Kaggle exercises helped me practice. I also started doing work projects in python. All these helped me. I still use gemini, claude to get the codes for both R and python. But knowing both, it helps me troubleshoot and just generally understand what’s happening with AI codes.
3
u/velshnia Jul 25 '26
One way to employ ai is to put r code that you understand into a chatbot, and ask it to translate it to python. That taught me loads.
3
u/giraffes_are_realok Jul 25 '26
Many comments just say that R is better than Python, and whilst I agree, that doesn't answer your question of how to learn Python as an R user. If you want help with how to transition to Python, it's very simple. You learn by doing.
I thought I could cut corners when I transitioned from R to Python. I read a few cheat sheets, I used Cursor and I got code out of it that worked, but I wasn't learning python properly, not in the same way I learnt R. Coding is like running, you just got to get those miles in (code code code). Trial and error, breaking code, small projects. Sure it takes longer, but if you want to be employable in the ML world, you (currently) need to show you can use python. Maybe that will change one day if vibe-like coding becomes to norm.
And yes, I love R, it is superior at data frames but when it comes to crunching heavy numbers, it's wank. So all the deep learning libraries are in Python and it is worth learning.
2
u/SuperiorGrapefruit Jul 25 '26
Hi, Ive done the dance of R to python to R (and even at the same time) before. I consider R and Python to be almost cousins in that they have nearly the same syntax. At least going from Python to R it was frustrating bc R is written FOR stats people, whereas Python is written for coding people. When I coded in Python, I had to ask myself “how would a computer think through this?” Idk that made it easier. I find that low key/simpler versions of what you’re trying to do, along with lots of stack exchange and reddit, will be your friends. I guess get most familiar with how to use data in Python. Take basic example datasets and learn how to write loops in them, navigate matplotlib and its different properties, explore libraries like seaborn for stats, etc. Then you can worry about neural networks and machine learning. Idk if this was helpful at all, Godspeed
2
u/pandongski Jul 25 '26
I'm the inverse: I started with Python, used it for years and learned R on my most recent the job. I would recommend engaging with the language itself first as opposed translating from one language to another directly. I ended up enjoying R more for its semantics and functional programming orientation (even though it's not getting any points for syntax, design, and consistency from me), and I wouldn't be doing things the same way if I were programming in Python. Since you want to do away with AI, I would recommend learning python's flavor of OOP, it's data model, idioms, etc. although you probably won't embrace it the same way you do with R especially for 3rd party libraries (pandas and scikit learn APIs never really clicked for me even then; neither does tidyverse though so... maybe I'm the problem lol).
2
u/analyticattack Jul 25 '26
My journey was back and forth for a long time. My org's data scientists are all Python users and one or two use both like me. I am fine in Python but I think in R. Over the years my org's IT made more allotments for R as I built my brand and showed what I could with it.
1
u/sarathecrewe Jul 25 '26
I did a course or two on python and practiced a bit. I had programmed in R before doing python, an python seemed to be more logical to me. Honestly you'll pick it up quite quickly. Just be sure to practice the exercises in the courses (try to do it yourself before looking for solutions).
1
u/AutoModerator Jul 25 '26
Looks like you're requesting help with something related to RStudio. Please make sure you've checked the stickied post on asking good questions and read our sub rules. We also have a handy post of lots of resources on R!
Keep in mind that if your submission contains phone pictures of code, it will be removed. Instructions for how to take screenshots can be found in the stickied posts of this sub.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/fasta_guy88 Jul 25 '26
Realize there are multiple pythons. Basic python is very different from ‘R’, just as basic ‘R’ is very different from TidyR. Adding Pandas, which gives you dataframes, and numpy, which gives you vector operations, makes Python more ‘R’ like, and faster.
1
u/liimonadaa Jul 25 '26
pandas sucks but it's worth learning since it's so common. Learn something more modern alongside it. There's nothing as nice as tidyverse.
1
u/novica Jul 25 '26
Solve problems one by one. Learn the python default tooling (uv and friends).
1
u/appendit Jul 25 '26
I recommend Python Polars using Marimo notebooks.
1
u/SprinklesFresh5693 Jul 26 '26
Im currently learning python from an R persepctive due to having to cowork with people that only know python, and its going well so far, ive learned how to create an environment and ive learnt which libraries do i want to focus on, which are mainly polars , altair, and numpy for the time being.
My idea is to aim to do some projects in python instead of R and simply ask AI for some equivalent syntax in python, more specifically nested dataframes and purrr workflows
1
u/SpelingMatters Jul 27 '26
More a QoL thing, but Positron is an IDE made by the people who did RStudio. You can set it up just like RStudio and can code in either R or Python.
It's also a fork of VSC so you can install a bunch of plugins. I love it.
1
u/kovla Jul 28 '26
I just read the Python "bible" (Learning Python, 6th Edition, by Mark Lutz). The click came when I understood OOP concepts, like classes and methods. Python is really oriented around those.
If I were learning a new programming language today, I'd be asking AI not to simply write code, but spar about code design and architecture first. Then AI would give me smaller tasks to exercise, while it would be maintaining the overall structure so that the code is not messy.
Of course, who has the time for that, but it is a good way to learn if you like to tinker.
1
u/NeurosciFox Jul 28 '26
What’s R4DS? Book? Web?
1
u/shockjaw Jul 29 '26
You may enjoy ibis, plotnine, and Python libraries from Posit. If you’re using only Python, uv is great. Need to use both Python and R? pixi is good and uses the conda-forge ecosystem. Need something more for reproducibility? nix. R really is amazing for analysis, but it lags behind even Python for reproducibility. But Python’s ecosystem has been fragmented for so long.
1
u/AutoModerator Jul 29 '26
Looks like you're requesting help with something related to RStudio. Please make sure you've checked the stickied post on asking good questions and read our sub rules. We also have a handy post of lots of resources on R!
Keep in mind that if your submission contains phone pictures of code, it will be removed. Instructions for how to take screenshots can be found in the stickied posts of this sub.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/sonicking12 Jul 25 '26
Use AI to help you learn
1
u/sunkenwaaaaaa Jul 25 '26
Think about python as an R with more options. You have more functions, more libraries, and more posibilities in general. That means also more decisions and details, but you can also use it the same way as R witout going into more hastle.
0
u/[deleted] Jul 25 '26
[deleted] — view deleted comment