Created
September 1, 2020 15:05
-
-
Save pr130/11e684797ce4e7e1bd5eb9a71f78a5d9 to your computer and use it in GitHub Desktop.
Python character list to rows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
library(tibble) | |
library(stringr) | |
library(tidyr) | |
py_list_vec <- c('["foo", "bar", "baz"]', '["test1", "tst2"]', '["a", "b", "c", "d", "e"]') | |
df <- tibble::tibble(id = c(1, 2, 3), x = py_list_vec) | |
df %>% | |
dplyr::mutate(x = stringr::str_replace(x, '\\[', "")) %>% | |
dplyr::mutate(x = stringr::str_replace(x, '\\]', "")) %>% | |
tidyr::separate_rows(x, sep = ",") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment