我在用连词造句.
我有一个包含列的数据帧
df = df[['fullName', 'Location', 'College', 'Degree_location', 'Degree', 'Jobs', 'Company', 'Date', 'LocationJob', 'Avg_rounded']]
我正在try 将列的每一行与硬编码的句子相匹配,即
name_placeholder = "My name is "
location_placeholder = "I live in "
college_placeholder = "I went to "
collloc_placeholder = " in "
degree_placeholder = "I have a degree in "
job_placeholder = "I have work as "
company_placeholder = " in companies "
date_placeholder = "I have work from "
jobloc_placeholder = "My job locations have been "
avgdistance_placeholder = "The average distance between my locations is "
placeholders = name_placeholder, location_placeholder, college_placeholder, collloc_placeholder, degree_placeholder, job_placeholder, company_placeholder, date_placeholder, jobloc_placeholder, avgdistance_placeholder
我希望故事的结尾会是"我的名字是[全名].我住在[地点].我上的是[学院]"等等.
如果我使用for循环来访问数据帧的行,即:
for x in profiles:
for y in x:
print(y)
我得到了预期的结果.
然而,我正在试着从数据框中造出句子.
我已经try
for x in profiles:
for y in x:
for pl, pr in zip(cycle(placeholders), y):
print(pl + pr)
但这给了我
My name is A
I live in d
I went to a
in m
I have a degree in
为什么数据框行打印每个字符而不是完整的字符串ie[fullName]?
根据我的理解,我组合了数据帧和占位符列表,并循环使用占位符,因为它的列表比数据帧短得多.
我哪里错了?