我想根據Pandas中的groupedby合併數據框中的幾個字符串。使用Pandas group連接來自多行的字符串byby
這是我到目前爲止的代碼:
import pandas as pd
from io import StringIO
data = StringIO("""
"name1","hej","2014-11-01"
"name1","du","2014-11-02"
"name1","aj","2014-12-01"
"name1","oj","2014-12-02"
"name2","fin","2014-11-01"
"name2","katt","2014-11-02"
"name2","mycket","2014-12-01"
"name2","lite","2014-12-01"
""")
# load string as stream into dataframe
df = pd.read_csv(data,header=0, names=["name","text","date"],parse_dates=[2])
# add column with month
df["month"] = df["date"].apply(lambda x: x.month)
我想最終的結果看起來是這樣:
我不明白我怎麼可以使用GROUPBY和應用一些在「文本」列中串聯字符串。任何幫助感謝!
請注意,這隻適用於一列一次。 – ybull 2017-10-18 19:27:23