I used snscrape to get the geolocation of tweets for mapping them on the world map. The resulted coordinates come in format {'longitude': -70.7729481, 'latitude': 42.0616232}.
How do I split the list into two columns like?
longitude | latitude |
---|---|
-70.7729 | 42.06162 |
I've tried unlist, read.table and few other ways I could find online but none of them work. It usually just ends up as
V1 | V2 |
---|---|
{'longitude': -70.7729481 | 'latitude': 42.0616232} |
CodePudding user response:
Looks like you deal with json data, you perhaps can do it right away from your json string.
library(jsonlite)
str <- '{"longitude" : -70.7729481, "latitude" : 42.0616232}'
data.frame(fromJSON(str))
# longitude latitude
# 1 -70.7729481 42.0616232
CodePudding user response:
string <- "{'longitude': -70.7729481, 'latitude': 42.0616232}"
data.frame(reticulate::py_eval(string))
longitude latitude
1 -70.77295 42.06162