如何做 this 的相反操作?
我有一个命名元组列表,是我通过迭代 pandas 数据框构建的:
list = []
for currRow in dataframe.itertuples():
list.append(currRow)
如何将这个命名元组列表转换为元组列表?请注意,itertuples() 返回命名元组。
请您参考如下方法:
你只需将它放入 tuple() 构造函数:
>>> from collections import namedtuple
>>> foo = namedtuple('foo', ('bar', 'baz'))
>>> nt = foo(1,2)
>>> nt
foo(bar=1, baz=2)
>>> tuple(nt)
(1, 2)
