我正在嘗試通過回傳我所做的一些預處理來修復我生成的一些句子。
Generated_sentence = "Had to wait @ minutes for the pizza"
我想將@符號改回數字。我創建了一個資料框,其中包含有關原始資料集中單詞分鐘之前的數字的中值和標準差的資訊。我也這樣做了。
這是此資料框的一部分
| word| median| std|
|---- |------| -----|
| minutes| 20| 20|
|pm|9|2|
|stars|3|2|
現在我想根據它后面的單詞更改@ back,所以在這種情況下是分鐘,然后我想根據中值和標準偏差生成一個數字。我怎么做?
uj5u.com熱心網友回復:
這應該可以滿足您的要求:
Generated_sentence = "Had to wait @ minutes for the pizza"
words = [x.strip() for x in Generated_sentence.split()]
word = words[words.index('@') 1]
sentence = Generated_sentence.replace('@', str(round(df.loc[df['word'] == word, 'median'].tolist()[0])))
輸入
word median std
0 minutes 20.5 20
1 pm 9.0 2
2 stars 3.0 2
輸出
Had to wait 20 minutes for the pizza
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/488320.html
