0

I've a column contains Arabic sentences. when I try reading it by Pandas.read_csv , it reads it like English from left to right and I aim to the opposite. e.g. row= [Egypt is big] I NEED : [big is Egypt] Thanks a lot

  • Please read the following documentation, then [edit](https://stackoverflow.com/posts/65964265/edit), and rephrase the question. [Take the Tour](https://stackoverflow.com/tour), [How to ask a good question](https://stackoverflow.com/help/how-to-ask), & [On Topic](https://stackoverflow.com/help/on-topic). Always provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) with code, data, errors, current & expected output, as [formatted text](https://stackoverflow.com/help/formatting). – k33da_the_bug Feb 12 '21 at 04:46

2 Answers2

0

What I would do is split the string into a list, reverse the list and then join the list using spaces.

s='This is a string'
(' ').join(s.split(' ')[::-1])

What this does is it splits the string on spaces into a list, [::-1] reverses the order of the list, and then you bring them back together using the join method.

stidmatt
  • 1,629
  • 13
  • 15
0

enter image description here

Have you tried something like this to reverse the string characterwise?

df = pd.DataFrame({'a': ['ab', 'cd']})
df['a'].apply(lambda x: x[::-1])
Tianhui Li
  • 101
  • 7