如何使用 python 在电报机器人中发送数据帧表

How to send dataframes tables in telegram bot using python

你能帮我在电报机器人中将数据帧作为 tables 发送吗?在我的案例中,我使用 aiogram。所以,这就是我写的:我使用

> 发送我的数据帧 y_data 作为 html-table.

async def unsubscribe(message: types.Message):
    remove_keyboard = types.ReplyKeyboardRemove()

    if message.chat.id in BOT_ACCESS_ID:
        df = read_file('metrics')

        # add message with table
        y_data = yesterday_data(df)
        await bot.send_message(message.chat.id,
                     f"Data:\n<pre>{y_data}</pre>", parse_mode='html', reply_markup=markup, reply_to_message_id=message.message_id,)
    else:
        await bot.send_message(message.chat.id, "You have no access")

问题是收到的带有 table 的消息没有包含所有的列。下面的照片可以显示我从电报机器人那里得到的结果消息:

并且我想显示所有列并删除关于行和列的描述。你能帮帮我吗?

您可以使用 pd.set_option('display.max_columns', None) 显示任意数量的列,使用 pd.set_option('display.max_rows', None) 显示任意数量的行。

import pandas as pd

pd.set_option('display.max_columns', None)

# Your code here