私のようなデータフレーム持っている:私はこれを行うことができることを知って)(str.formatに名前付き引数として列を持つデータフレームを使用して
import pandas as pd
df = pd.DataFrame({'author':["Melville","Hemingway","Faulkner"],
'title':["Moby Dick","The Sun Also Rises","The Sound and the Fury"],
'subject':["whaling","bullfighting","a messed-up family"]
})
:
# produces desired output
("Some guy " + df['author'] + " wrote a book called " +
df['title'] + " that uses " + df['subject'] +
" as a metaphor for the human condition.")
だけに、それは可能であるが
# returns KeyError:'author'
["Some guy {author} wrote a book called {title} that uses "
"{subject} as a metaphor for the human condition.".format(x)
for x in df.itertuples(index=False)]
これで、 '*'は私のタプル部分を行います。輝かしい、ありがとう - なぜ誰かが私たちをdownvoted理由 – C8H10N4O2