- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What does the pandas.series.values attribute do?
A pandas series object is used to store 1-dimensional labeled data, that data is called values and the labels are called indexes in pandas.
In pandas data structures we can store any kind of data like text data, integer values, and time sequence, and more. We can access series elements by using the respected labels. instead of accessing elements by labels, we can get all elements in a ndarray type object.
Example1
import pandas as pd # creating a series s = pd.Series([10,10,20,30,40]) print(s) # Getting values values = s.values print('Output: ') # displaying outputs print(values)
Explanation
Initially, we have created a pandas Series object with a list of integer values. And The “.values” attribute applied to the series object then will return a ndarray with series values.
Output
0 10 1 10 2 20 3 30 4 40 dtype: int64 Output: [10 10 20 30 40]
The “.values” attribute accesses the values in the serial object and returns a ndarray object with values. Those two objects are displayed in the above output block.
Example 2
import pandas as pd s = pd.Series({97:'a', 98:'b', 99:'c', 100:'d', 101:'e', 102:'f'}) print(s) # Getting values values = s.values print('Output: ') # displaying outputs print(values)
Explanation
In the following example, we have created another pandas series object with string data. For that we have initialized a python dictionary then applied it to the pandas.Series constructor.
Here our goal is to apply the ".values” attribute to see the result output object to see the values in the given pandas series.
Output
97 a 98 b 99 c 100 d 101 e 102 f dtype: object Output: ['a' 'b' 'c' 'd' 'e' 'f']
The s.values attribute will return a ndarray of all values in given series, for the following example the given series object “s” is only having string type data.
Apply type() function to verify which type of python object is returned as an output for this .values attribute.
- Related Articles
- What does the pandas DataFrame.index attribute do?
- What does the pandas DataFrame.columns attribute do?
- What does count method do in the pandas series?
- What does the all() method do in pandas series?
- What does agg() method do in pandas series?
- What does the add() method do in the pandas series?
- What does the align() method do in the pandas series?
- What does the any() method do in the pandas series?
- What does the apply() method do in the pandas series?
- What does the pandas.series.array attribute do?
- What does the pandas.series.index attribute do?
- How does pandas series argsort handles nan values?
- What do axes attribute in the pandas DataFrame?
- What does series mean in pandas?
- What does axes in the pandas series mean?
