2024-10-02 22:30:41 发布
网友
我在看代码:
https://ahmedbesbes.com/how-to-mine-newsfeed-data-and-extract-interactive-insights-in-python.html
news = pd.DataFrame(reduce(lambda x,y: x+y ,map(lambda r: r['articles'], responses)))
有人能解释一下这句台词吗?map/reduce操作在这里做什么?在
{cda>仅限函数。以及map,它将在列表中的每个元素中应用该函数。reduce将基于函数将列表设为单个值。在
map
reduce
这个操作用一个小例子来描述
In [2]: res Out[2]: [{'articles': 124, 'other': 234}, {'articles': 124, 'other': 234}, {'articles': 124, 'other': 234}] In [3]: map(lambda r: r['articles'], res) Out[3]: [124, 124, 124] In [4]: reduce(lambda x,y:x+y,[124, 124, 124]) Out[4]: 372
希望你能理解
{cda>仅限函数。以及
map
,它将在列表中的每个元素中应用该函数。reduce
将基于函数将列表设为单个值。在这个操作用一个小例子来描述
希望你能理解
相关问题 更多 >
编程相关推荐