I have a simple Telegram Bot with python-telegram-bot package and i use pandas to import a csv:
df = pd.read_csv('data.csv')
| key | text |
|---|---|
| 00 | text1 \n text2 \n text3 |
| . | some \n text |
| . | other \n text |
| 99 | text4 \n text5 \n text6 |
Then I do a search inside the dataframe from user message:
answer = df['text'].str.contains(update.message.text, case=False)]
and the bot sends a reply message to the user:
await update.message.reply_text(answer)
but the output is showing the "\n" tag:
text1 \n text2 \n text3
and I want to show the text:
text1
text2
text3
I'm struggling with this problem. Before dataframe I used TinyDb and everything worked fine. How can I resolve?
Thanks
I try to change dtype of column to string, to export csv to list, encoding of the file.
I tried what happened in your case, but it worked for me.
Image result in telegram
With csv data:
Output:
When we work with csv, we will get
\\n, we can change\\nto\nto get the result we need.Working with unicode, we need a unicode escape sequence and replace it with Unicode characters using the
unicode_escapecodec.A simple way we can use a regex expression like that:
Output: