如何在 python 数据框中合并具有相同日期的文本?
How can I combine the texts with same date in the python dataframe?
我有以下数据框,我想在一个日期收集具有相同日期的文本。
date text
2020-09-10 text1
2020-09-10 text2
2020-09-09 text3
2020-09-09 text4
2020-09-08 text5
2020-09-08 text6
我期望的数据框就是这样。
date text
2020-09-10 text1text2
2020-09-09 text3text4
2020-09-08 text5text6
df.groupby('date').agg({'text':'sum'})
date text
2020-09-10 text1text2
2020-09-09 text3text4
2020-09-08 text5text6
这应该可以解决问题。
import numpy as np
import pandas as pd
df = pd.DataFrame({'date': ['2020-09-10','2020-09-10','2020-09-09','2020-09-
09','2020-09-08','2020-09-08'],'text':['134','13','2','3','4','5']})
df.groupby('date')['text'].sum()
我有以下数据框,我想在一个日期收集具有相同日期的文本。
date text
2020-09-10 text1
2020-09-10 text2
2020-09-09 text3
2020-09-09 text4
2020-09-08 text5
2020-09-08 text6
我期望的数据框就是这样。
date text
2020-09-10 text1text2
2020-09-09 text3text4
2020-09-08 text5text6
df.groupby('date').agg({'text':'sum'})
date text
2020-09-10 text1text2
2020-09-09 text3text4
2020-09-08 text5text6
这应该可以解决问题。
import numpy as np
import pandas as pd
df = pd.DataFrame({'date': ['2020-09-10','2020-09-10','2020-09-09','2020-09-
09','2020-09-08','2020-09-08'],'text':['134','13','2','3','4','5']})
df.groupby('date')['text'].sum()