I'm currently transitioning from R to Python in my data analysis, and there's one thing I haven't seen in any tutorials out there: is there anything in Pandas similar to dplyr's 'list columns' ?
As for nesting dataframes within one another, it is possible but, I believe it's considered an anti-pattern, and pandas will fight you the whole way there:
发布评论
评论(1)
pandas
将在对象类型列中接受任何对象类型,包括列表。我们可以看到:
类型
是列表列。dtype
类型
列是object
genre
的第一个值的类型 code> list <列表< /代码>。有许多与列表一起使用的
str
功能。例如:
如果没有内置方法,则通常可以使用
应用
函数来完成:请参阅文档以获取更多...
彼此之间的嵌套数据帧,它是可能的,但是,我相信它被认为是一个反模式,
pandas
将在此处与您打击:<
link2将它们存储为
numpy
数组:pandas
will accept any object type, including lists, in an object type column.We can see that:
genre
is a column of lists.dtype
of thegenre
column isobject
genre
islist
.There are a number of
str
functions that work with lists.For example:
Others can typically be done with an
apply
function if there isn't a built-in method:See the documentation for more... pandas str functions
As for nesting dataframes within one another, it is possible but, I believe it's considered an anti-pattern, and
pandas
will fight you the whole way there:See:
A possibly acceptable work around, would be storing them as
numpy
arrays: