Indexes and Values
Series in pandas
differ from numpy
arrays in that they have indexes. These can be integers, floating-point numbers, strings, time series.
To get the series' indexes, use the .index
attribute of a series object. To get values, use the values
attribute. By default, indexes are integers starting from 0, but if you want to change them, you simply may reassign new list of indexes to the .index
attribute. For instance,
12345678910111213# Importing library import pandas as pd # Creating pandas series ser = pd.Series([1000, 2500, 1700]) # Getting series' indexes and values print(ser.index) print(ser.values) print(ser) # Changing series' indexes ser.index = ['first', 'second', 'third'] print(ser)
As you can see, initial indexes were 0, 1, 2
. After changing, they became 'first', 'second', 'third'
.
Grazie per i tuoi commenti!
Chieda ad AI
Chieda ad AI
Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione
Mi faccia domande su questo argomento
Riassuma questo capitolo
Mostri esempi dal mondo reale
Awesome!
Completion rate improved to 3.33
Indexes and Values
Scorri per mostrare il menu
Series in pandas
differ from numpy
arrays in that they have indexes. These can be integers, floating-point numbers, strings, time series.
To get the series' indexes, use the .index
attribute of a series object. To get values, use the values
attribute. By default, indexes are integers starting from 0, but if you want to change them, you simply may reassign new list of indexes to the .index
attribute. For instance,
12345678910111213# Importing library import pandas as pd # Creating pandas series ser = pd.Series([1000, 2500, 1700]) # Getting series' indexes and values print(ser.index) print(ser.values) print(ser) # Changing series' indexes ser.index = ['first', 'second', 'third'] print(ser)
As you can see, initial indexes were 0, 1, 2
. After changing, they became 'first', 'second', 'third'
.
Grazie per i tuoi commenti!