私は以下のデータフレームに2つのシリーズを持っています。最初の文字列は2番目に表示される文字列で、これはURL文字列になります。私がしたいのは、余分な文字を連結して最初のシリーズを変更し、その変更を2番目の文字列に適用することです。パンダの分割と参加シリーズ
import pandas as pd
#import urlparse
d = {'OrigWord' : ['bunny', 'bear', 'bull'], 'WordinUrl' : ['http://www.animal.com/bunny/ear.html', 'http://www.animal.com/bear/ear.html', 'http://www.animal.com/bull/ear.html'] }
df = pd.DataFrame(d)
def trial(source_col, dest_col):
splitter = dest_col.str.split(str(source_col))
print type(splitter)
print splitter
res = 'angry_' + str(source_col).join(splitter)
return res
df['Final'] = df.applymap(trial(df.OrigWord, df.WordinUrl))
私はその後dest_col
内の文字列にその変化をもたらす、dest_col
にその文字列にsplit
、その後、find the string from the source_col
にしようとしています。ここで私はFinal
と呼ばれる新しいシリーズとしてそれを持っていますが、私はむしろインプレースです。私は主な問題はsplitter
変数であり、機能していないと考えています。ここで
は、結果がどのように見えるべきかです:
OrigWord WordinUrl
angry_bunny http://www.animal.com/angry_bunny/ear.html
angry_bear http://www.animal.com/angry_bear/ear.html
angry_bull http://www.animal.com/angry_bull/ear.html
これはインプレースと関数を作成する必要がないため、ラムダを使用するだけで最高の答えです。ありがとう – noblerthanoedipus