【发布时间】:2019-10-13 07:54:07
【问题描述】:
我需要在对象的 DataFrame 中重置一些值
import pandas as pd
import numpy as np
df = pd.DataFrame({
'x': [[0] * 6, ['']],
'y': [[0, np.nan, 0, 1, 0, 1], [4, 3, 5]],
'z': [[5, 5, 5, 4, 4, 4], [65, 324, 45.345]]
})
def test(ar):
if ar == ['']:
return False
else:
return True
df.applymap(test)
applymap 返回这个:
我只需要将带有True 的列和单元格放入如下结构:
d = {
'x': [(0, [''])],
'y': [(0, ['']), (1, ['']),]
'z': [(0, ['']), (1, ['']),]
}
实现这一目标的最快方法是什么?必须有一个简单的方法来解决它。
【问题讨论】:
-
你问的是如何获取单元格的列索引?
标签: python python-3.x pandas dataframe mapping