I am creating a function to convert a dataframe to a .txt file.
import pandas as pd
def print_table(dataframe):
headers = dataframe.columns.to_list()
table = dataframe.values.tolist()
with open('file.txt','w') as file:
file.write(''.join(column.rjust(40) for column in headers))
for row in table:
with open('file.txt','w') as file1:
file1.write(''.join(str(column).ljust(20) for column in row))
df = pd.DataFrame({'Yoruba': ['Wèrè èèyàn ní ńwípé irú òun ò sí; irú ẹ̀ẹ́ pọ̀ ó ju ẹgbàágbèje lọ.','Wọ́n ńpe gbẹ́nàgbẹ́nà ẹyẹ àkókó ńyọjú.'],
'Translation': ['Only an imbecile asserts that there is none like him or her; his or her likes are numerous, numbering more than millions.',
'The call goes out for a carpenter and the woodpecker presents itself.'],
'Meaning': ['No one is incomparable.',
"One should not think too much of one's capabilities."]})
This is how i want the .txt file to look like
Yoruba Translation Meaning
"Wèrè èèyàn ní ńwípé irú òun ò sí; irú ẹ̀ẹ́ pọ̀ ó ju ẹgbàágbèje lọ." "Only an imbecile asserts that there is none like him or her; his or her likes are numerous, numbering more than millions." "No one is incomparable."
"Wọ́n ńpe gbẹ́nàgbẹ́nà ẹyẹ àkókó ńyọjú." "The call goes out for a carpenter and the woodpecker presents itself." "One should not think too much of one's capabilities."
**and not this**
Yoruba Translation Meaning
"Wèrè èèyàn ní ńwípé irú òun ò sí; irú ẹ̀ẹ́ pọ̀ ó ju ẹgbàágbèje lọ." "Only an imbecile asserts that there is none like him or her; his or her likes are numerous, numbering more than millions." "No one is incomparable."
"Wọ́n ńpe gbẹ́nàgbẹ́nà ẹyẹ àkókó ńyọjú." "The call goes out for a carpenter and the woodpecker presents itself." "One should not think too much of one's capabilities."
But this is the error i am getting
UnicodeEncodeError: 'charmap' codec can't encode character '\u0144' in position 14: character maps to