[英]Skip Rows in CSV to List Python
I am new to python and am trying to build an sms app with twilio and am running into the following issue.我是 python 新手,正在尝试使用 twilio 构建一个短信应用程序,但遇到了以下问题。 I have a csv file that contains 3 columns:
Numbers, Name, Link
i converted each column to a separate list by doing:我有一个包含 3 列的 csv 文件:
Numbers, Name, Link
我通过执行以下操作将每一列转换为单独的列表:
from pandas import *
columns = read_csv("file path")
phone_number = columns['Numbers'].tolist()
last_name = columns['Name'].tolist()
link = columns['Link'].to_list()
Im trying to skip "rows" if a certain number is found.如果找到某个数字,我试图跳过“行”。 For example if
Number = 8001234567
i want to skip that and its associated name an link and continue messaging the other numbers, names and links out.例如,如果
Number = 8001234567
我想跳过该链接及其关联名称,并继续向其他数字、名称和链接发送消息。 this is what i have so far:这是我到目前为止所拥有的:
def send_message(num, lname, link):
message = twilio_client.messages.create(
body= 'Hi ' + lname + ',\n\n This is a test. Heres a link: ' + link,
from_= my_number,
to= num)
for (n, ln, lk) in zip(phone_number, last_name, link):
if n =='8001234567':
continue
time.sleep(5)
send_message(num=n, lname=ln, link=lk)
No message is being sent for some reason but if i delete parameters and variables out of body
it sends the right amount of messages.由于某种原因没有发送任何消息,但如果我从
body
中删除参数和变量,它会发送适量的消息。
I have reformatted your code a bit.我已经重新格式化了你的代码。
twilio_client.messages.create
accepts body, from_, to as strings only. twilio_client.messages.create
接受正文 from_ to 作为字符串。
import pandas as pd
df = pd.read_csv("file path")
df = df[df['Numbers'].astype(str) != '8001234567']
def send_message(num, lname, link):
message = twilio_client.messages.create(
body= f'Hi {lname} \n\n This is a test. Heres a link:',
from_= my_number
media_url=[link],
to= num)
for i in range(df.shape[0])
n, ln, lk = df.iloc[i,:].values
send_message(num=str(n), lname=str(ln), link=str(lk))
time.sleep(5)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.