[英]Reading Pandas data frame stored with Feather into R
I just attempted to read into R a Pandas dataframe stored to disk with Feather. 我只是试图将用Feather存储到磁盘的Pandas数据帧读入R。 After reading the dataframe in, I checked the type of the object and instead of seeing 'data.frame'
as the result, I see 'tbl_df' 'tbl' 'data.frame'
. 读入数据框后,我检查了对象的类型,而不是看到'data.frame'
作为结果,而是看到了'tbl_df' 'tbl' 'data.frame'
。 Any idea what is going on here? 知道这里发生了什么吗?
Relevant code is simply: contact_records_df <- read_feather('contact_records.feather') class(contact_records_df)
相关代码很简单: contact_records_df <- read_feather('contact_records.feather') class(contact_records_df)
It's just brought it in as a tibble, which is more or less an 'enhanced' dataframe from the tidyverse world. 它只是作为小标题而引入的,它或多或少是来自dydyverse世界的“增强型”数据框。 You can see the docs here 您可以在这里查看文档
You can use them interchangably with dataframes. 您可以将它们与数据帧互换使用。 I have noticed once in awhile, especially with spatial functions, that tibbles cause something to die so you sometimes have to convert them back to a dataframe. 我偶尔会注意到,尤其是对于空间函数,小滴会导致某些东西死掉,因此有时您必须将它们转换回数据帧。
library(tibble)
x1 <- c(1, 2, 3, 4)
x2 <- c("one", "two", "three", "four")
example_df <- data.frame(x1,x2)
example_tibble <- tibble(x1,x2)
If you check out the two of them using str
, you'll see they are basically the same except tibbles won't auto convert strings to factors (among other things). 如果使用str
检查它们两个,您会发现它们基本相同,只是小技巧不会自动将字符串转换为因数(除其他外)。
> str(example_df)
'data.frame': 4 obs. of 2 variables:
$ x1: num 1 2 3 4
$ x2: Factor w/ 4 levels "four","one","three",..: 2 4 3 1
> str(example_tibble)
Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 4 obs. of 2 variables:
$ x1: num 1 2 3 4
$ x2: chr "one" "two" "three" "four"
Also, it's still a dataframe but it has some more specific classes 另外,它仍然是一个数据框,但具有一些更具体的类
> is.data.frame(example_tibble)
[1] TRUE
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.