-1

Assume a dataframe df -

df = pd.DataFrame(['a'])

I want to extract the string 'a' from this dataframe. I tried to extract it by trying the following from stackoverflow answers - Attempt 1 -

print(df.iloc[0])
>>0    a
Name: 0, dtype: object

Attempt 2 -

print(df.astype(str))
>>  0
0  a

Please help me extract the string 'a' from the dataframe

0

1 Answer 1

1

With iloc you getting the first series from dataframe. If you want first element of that series you should use it twice or with iloc[0][0]:

In [57]: df.iloc[0][0]
Out[57]: 'a'

In [58]: df.iloc[0].iloc[0]
Out[58]: 'a'
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.