4 ms·
R is a but of a horror show under the hood, I agree, but if you're just an end user doing data analysis, consider: flights.iloc[0:10, flights.columns.get_i
by hyperbovine 6y ago
R is a but of a horror show under the hood, I agree, but if you're just an end user doing data analysis, consider:
flights.iloc[0:10, flights.columns.get_indexer(['year', 'month', 'day'])])
versus
flights %>% select("year", "month", "day") %>% head(10)
I could go on...
- totalperspectiv 6y agoI totally agree that it is a very efficient and powerful tool for ad-hoc data analysis. It's just not what I would view as a responsible choice for production / publication code.
- kgwgk 6y agoYou could have done flights[['year', 'month', 'day']].head(10) which is not so different from standard R head(flights[c("year", "month", "day")], 10) but it's true that the following may be nicer flights[1:10, c("year", "month", "day")] (by the way using head(10) is not the same as indexing 1:10 if there are less than 10 rows)
- superbatfish 6y agoflights[["year", "month", "day"]].head(10)
- _Wintermute 6y agoThat's a very dishonest example. Yes, terribly written pandas code looks terrible.
- nojito 6y agoflights[1:10, .(year, month, day)] for the data.table fans Which is arguably the superior way to handle tabular data in 2020.
- empthought 6y agoIt’s pretty sad that both are worse than SELECT year, month, day FROM flights LIMIT 10
- Tarq0n 6y agoSELECT before FROM isn't really a good thing.