After I published an article on how to scrape advanced shooting data from stat.nba.com, a friend of mine contact me to see whether I may be able to scrape some data from zipcar or car2go’s API. So I looked into it and found it is quite straight forward to do. Here is an example to scrape data from car2go. Car2go is a popular car sharing program in North America and Europe. Here is a little introduction from Wiki if you haven’t about it: The company offers exclusively Smart Fortwo vehicles and features one-way point-to-point rentals. Users are charged by the minute, with hourly and daily rates available. As of May 2015, car2go is the largest carsharing company in the world with over 1,000,000 members. A typical URL looks like this. Anything after json is not needed. After putting it into R (using jsonlite), you will see a list of 1 data frame. However, the column coordinates need special attention as it is also a list. Therefore it is treated differently as other columns, and then they are then 'cbind'ed. Also note cities with EVs have an attribute of 'charging' while others don't, in order to have a consistent sata structure, I first identify those cities based on length() of the data. Then incert a charging column into those that don't have and assign a value of NA. A for loop can be used to scrape data from different cities, an if statement will automatically identify which data processing code to use. Finally, all the data can be 'rbind'ed and output a csv. It is also quite easy to display all the cars on a map at a give time. Below is one example. I used the ggmap library. Color of each vehicle is to show how much fuel left. The result is the plot at the beginning of the blog. How about the average cleanness of cars in each city? or fuel level? For limited sample size, it seems German cities have the highest car cleanness, Italian cites the lowest, while US cities are in the middle.
The entire code is published here if you are interested. Enjoy!
7 Comments
8/20/2016 11:53:03 pm
After I published an article on how to scrape advanced shooting data from stat.nba.com, a friend of mine contact me to see whether
Reply
10/19/2016 03:16:53 am
Buying cars from a rental car agency will help the customer save lot of money on the purchase and buy a car which is not very bad either. We would, in this article, look at some of the things that must be kept in mind while buying cars from a car rental agency.
Reply
12/29/2016 10:51:37 am
This is an amazing blog regarding cars. car sharing is a good programme to share your cars. We are in the car maintenance department. Visit us for more information.
Reply
3/21/2017 05:50:17 am
I think this is very informative but might be a tad bit dangerous, if you ask me! Everything is published online right now - what about data privacy?
Reply
3/9/2018 08:40:38 am
have a car desirable is the desire of any person. I like your article. Thanks
Reply
Matilda
3/26/2019 08:01:51 pm
THANKS
Reply
Leave a Reply. |
AuthorA mechanical engineer who also loves data. Archives
January 2018
CategoriesBlogs I enjoy reading |