Python divmod为pandas Dataframe中的每个值

Cha*_*ron 2 python python-2.7 pandas divmod

我有一个像这样的pandas数据框:

   P-101  P-103  P-104  P-107  P-114  P-120
P   2415   2535   3345   5650   2805   6210
S      0     45   3105   1165      0      0
D      0    690    690    570    255    830
Run Code Online (Sandbox Code Playgroud)

我想对divmod(value, 60)每个单元格应用a ,然后将结果格式化为[quotient]h[remainder]m,如下所示:5h30m

我试过了:

df.values.apply(lambda x: divmod(x,60))
Run Code Online (Sandbox Code Playgroud)

但那抛出了一个 AttributeError

我如何申请divmod每一个价值?

Ian*_*anS 6

您正在寻找applymap,在以下情况下,它应用元素而不是行或列apply:

df.applymap(lambda x: divmod(x,60))
Run Code Online (Sandbox Code Playgroud)