我想知道以下代码的import pandas as pd
df_apple = pd.DataFrame({'_id': ['A', 'B', 'C'],
'apple': ['1', '0', '1'],
'orange': ['1', '1', '0'],
'kiwi': ['1', '0', '1']})
df_counts = df_apple.groupby(by=tuple(df_apple.columns[1:])).count()
idx_str = [[df_counts.index.names[i] for i, v in enumerate(idx) if v != '0']
for idx in df_counts.index]
idx_str = [" and ".join((", ".join(s[:-1]), s[-1])) if len(s) > 1 else s[0] for s in idx_str]
df_counts.index = idx_str
df_counts.columns = ["count"]
df_counts = df_counts.T
print(df_counts)
>>> orange apple and kiwi apple, kiwi and orange
count 1 1 1
.... datatype
或number
?
date
答案 0 :(得分:2)
[TL; DR] 从另一个中减去一个DATE
会给出天数差异作为数字。乘以24并舍入它不会改变数据类型。
(从另一个中减去一个TIMESTAMP
会将差异视为INTERVAL DAY TO SECOND
数据类型)
更长的答案:
SELECT DUMP( round(24*(sysdate - to_date('18-09-18 06:30','YYYY-MM-DD HH24 Mi'))) )
FROM DUAL
(注意:to_date('18-09-18 06:30','YYYY-MM-DD HH24 Mi')
将提供一年0018
而非2018
!)
输出:
Typ=2, Len=5: 196, 18, 53, 30, 33