Function to get the next character of a giving position of strings of a dataframe I want to get the next character giving a position of a another character of a string in a dataframe. If we have browsed every character of a string I should go to the next line.

And to do so I have written the function bellow.

def get_char(df, y, z):
    if z &lt; len(df[0][y])-1: 
        return df[0][y][z+1]
    elif z == len(df[0][y])-1:
        if y &lt; len(df[0])-1:
            return df[0][y+1][0]


so for the dataframe :

ar = np.array(["aba", "bcb", "zab"])
df = pd.DataFrame(ar)


if I

print get_char(df, 1, 2)


gives me z

and

print get_char(df, 2, 2)


should return nothing , in my function it returns None

I am pretty sure that I can do it with a much easier way.

My dataframe will have only one column.
Maybe this helps?  It will save you some if statements by just joining strings (although it will only read one position to the next dataframe element at the right in case you're in the last character of the y item). 

So take care in case you have empty strings and you want your search to keep jumping over to the next item (in that case you can just delete y+2 in the code and leave [y:,0].

import numpy as np
import pandas as pd

ar = np.array(["aba", "bcb", "zab"])
df = pd.DataFrame(ar)

def get_char(df, y, z):
    a = ''.join(df.iloc[y:y+2,0])
    try:
        return a[z+1]
    except:
        return None

print(get_char(df, 1, 2))
# z
print(get_char(df, 2, 2))
# None