'columns.values is not returning the strings

I have a dataframe with column name msg that has string values.

I am trying to get this values using:

df['msg'].values

But I am getting integers(problaby the index of the dataframe) and not the texts.

What am I doing wrong?



Solution 1:[1]

Say you have a pandas dataframe with column 'msg':

 df['msg'] = ['red', 'orange', 'yellow', 'green', 'blue', 'purple']

You can print just the string values with just:

 df['msg'].values** --> **['red', 'orange', 'yellow', 'green', 'blue', 'purple']

In order to print the index:

 df['msg'].index.to_list()** --> **[0, 1, 2, 3, 4, 5]

You can print certain string values by indexing. If you wanted the first string value:

 df['msg'][0] --> 'red'

Or last value:

 df['msg'][5] --> 'purple'**

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ouflak