-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

Rohan Bapat
  • 343
  • 2
  • 4
  • 17

1 Answers1

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'
Anton Protopopov
  • 30,354
  • 12
  • 88
  • 93