Home > Software engineering >  How to send dataframes tables in telegram bot using python
How to send dataframes tables in telegram bot using python

Time:03-24

Could you, please, help me with sending dataframes as tables in telegram bot. I use aiogram in my case. So, that's what I wrote: I used <pre> to send my dataframe y_data as a 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")

The problem is that the received message with such a table doesn't contain all the columns. The photo below can show the result message I got from my telegram bot:

enter image description here

And I wanted to show all the columns and delete the description about the rows and columns. Can you help me, please?

CodePudding user response:

You can use pd.set_option('display.max_columns', None) to display any number of columns and pd.set_option('display.max_rows', None) to display any number of rows.

import pandas as pd

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

# Your code here
  • Related