I'm writing this on my way back home from Bengaluru (Bangalore), where I had a wonderful time participating in PyCon India 2025. I attended interesting talks, spoke with smart people doing amazing things, met with companies interested in my Python/Pandas training services, and even got to tour the city a little. I had a marvelous time, and hope to return to India in the near future.
For me, one of the wildest parts of my trip was just seeing traffic go by. There were cars, but there were also many motorbikes and "tuk-tuks," basically enclosed motorbikes with a separate, wide passenger seat. (If you use Uber, tuk-tuks are even one of the listed, cheaper options.) There were some lane markers on the road, but I doubt anyone was looking at them. Everyone just squeezed in where they could.
The near lack of traffic lights and crosswalks, and the fact that no one really paid attention to them, made crossing the street a challenge. I often tried to cross with locals, but there were times when I did it myself, and it was ... nerve-wracking.
Part of the problem, locals told me, is that Bangalore has grown so quickly that the traffic infrastructure hasn't caught up. So yes, they're expanding the metro, and yes, they're adding new high-speed roadways, and yes, they're fixing roads – but they're doing so at a much slower pace than is needed for the rapidly growing population. So while the roads are full and chaotic, traffic moves slowly. One local said he lives 10 km away, an hour-long drive. I stayed about 40 km from the airport, and it took my taxi two hours to get there, even though we started at 7:30 p.m., not exactly rush hour.
These experiences led me to wonder: How many vehicles are there in Bangalore? How does that rank among all Indian states? How fast have these numbers been climbing? And what kinds of vehicles are most popular?
This week, we'll thus look at Indian government data about new vehicle registrations. That's not a perfect metric of what I'm trying to understand, but it will give us some insights into what's happening on the roads.
Data and five questions
This week's data comes from the Indian government's "VAHAN registration by maker" data set, allowing us to see how many new vehicles of each type were registered each year. The main page is at https://ckandev.indiadataportal.com/dataset/vehicle-registrations , and it offers a number of different files, all taken from a larger data set. Of the five listed there, we'll just be looking at three -- those for makers (i.e., which company manufactured the vehicle), class (i.e., what type of vehicle it is), and fuel type (to see how electric cars are doing).
I got each of these files in CSV format by clicking on the "explore" menu button next to the particular file I wanted, and then choosing "download."
The data starts in 2020 and ends halfway through last year (i.e., in 2024), so we aren't going to have a long historical perspective. But we will be able to compare numbers over time, compare states with one another, and even get a sense of how many cars vs. motorbikes are being registered. (I can already tell you, before doing the analysis, that motorbikes will overwhelm the number of four-wheeled vehicle purchases.)
Learning goals for this week: Grouping, window functions, pivot tables, and plotting with Plotly.
Paid members, including members of my LernerPython + data subscription program at https://LernerPython.com , can download all of the CSV files in a single zipfile from a link at the bottom of this message.
I'll be back tomorrow with my solutions and explanations. Meanwhile, here are my five tasks and questions:
- Load the "vehicle class" data into a Pandas data frame. Transform it into a data frame in which the rows represent years and the columns show the number of new vehicles of each class registered in that year. Using Plotly, create a stacked bar plot with one bar per year. Have overall vehicle registrations gone up each year? Do we see any trend?
- Now calculate the trend from year to year, for each vehicle class. In 2023, the last full year for which we have data, which five vehicle types increased their registration numbers, percentage-wise, the most? What if we limit our search to only the state of Karnataka?