gpt4 book ai didi

python - Telegram Bot 。如何在 Telegram 消息中打印DataFrame?

转载 作者:太空宇宙 更新时间:2023-11-03 20:58:11 32 4
gpt4 key购买 nike

所以我正在使用 pyTelegramBotApi 制作我的第一个 Telegram Bot 。问题是:我的机器人中包含一个 pandas DataFrame。当用户向机器人发送一些特殊文本时,机器人需要将此 DataFrame 发送给用户。我是通过将 DataFrame 转换为字符串值来实现的:

table = df.to_string(columns = ['Name', 'Description'], index = False, header = False, line_width = 70, justify = 'left')

bot.send_message(message.chat.id, table)

(而且我无法将其左对齐,它总是居中)

还有其他办法吗?

最佳答案

在下面的代码中,我使用“parse_mode”是HTML,事实上我昨天也做了同样的事情:

 var HTML = '<b>Top Brackets</b>\n-------------------------------------------------------------\n
Type Name Class Total
\n-------------------------------------------------------------\n';
var data = response.data;
for(var i=0;i<data.length;i++){
// $.sendMessage('<b>I am Bold</b>\n<i>I am italic</i>',{parse_mode: "HTML"});
HTML += `<b>${data[i].type}</b> ${data[i].name}} ${data[i].class}% ${data[i].total_unit}\n`
}
HTML +='\n\nUpdated 3 sec ago.\nWebiste : www.abc.com';
$.sendMessage(HTML,{parse_mode: "HTML"});
//bot.sendMessage(id,HTML,{parse_mode: "HTML"}) /*THE IMPORTANT ONE */

关于python - Telegram Bot 。如何在 Telegram 消息中打印DataFrame?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55875093/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com