将string_to_convert = "no me llama mucho la atenci\u00f3n"
print(json.dumps(json.loads(r'"%s"' % string_to_convert),ensure_ascii=False))
output: no me llama mucho la atención
与named aggregations
一起使用(GroupBy.agg
的最佳做法)
命名聚合的优点是我们可以聚合并同时重命名我们的列,请参见输出中的pandas >= 0.25.0
。
time_duration
df['time'] = pd.to_datetime(df['time'])
dfg = df.groupby('ID').agg(
time_duration=('time',lambda x: x.max()-x.min()),text=('text',' '.join)
).reset_index()
,
我们可以做到
df.groupby('ID').agg({'time':np.ptp,'text':' '.join})
Out[49]:
time text
ID
1 00:00:34 one day this code will help someone.
2 00:00:29 yes I'm feeling good.
,
分组和聚合:
(df.groupby('ID',as_index=False)
.agg({'time': lambda x: (x.max() - x.min()).total_seconds(),'text': ' '.join})
)
输出:
ID time text
0 1 34.0 one day this code will help someone.
1 2 29.0 yes I'm feeling good.
本文链接:https://www.f2er.com/3156559.html