Set_index () pandas

Ejemplos de código

7
0

cómo cambiar indeces en pandas dataframe

>>> df.set_index('month')
       year  sale
month
1      2012    55
4      2014    40
7      2013    84
10     2014    31
7
0

pandas de reset_index

df.reset_index(drop=True, inplace=True)
5
0

establecer el índice de la columna de los pandas

# method A
df = df.set_index('col')
# method B
df['col'] = df.index
4
0

cómo cambiar el índice en dataframe python

index = [1,2]
df.index = index
3
0

los pandas crear una columna de índice

df.reset_index(level=0, inplace=True)
3
0

cómo establecer el índice de pandas

# assignment copy
df = df.set_index('month')

# or inplace
df.set_index('month', inplace=True)

#      year   sale  month            month  year   sale
#  0   2012   55    1                1      2012   55
#  1   2014   40    4       =>       4      2014   40
#  2   2013   84    7                7      2013   84
#  3   2014   31    10               10     2014   31
2
0

establecer índice en datarame

df = df.set_index('col')
1
0

cómo configurar pandas índice

# assignment copy
df = df.set_index('month')

# or inplace
df.set_index('month', inplace=True)

#      year   sale  month            month  year   sale
#  0   2012   55    1                1      2012   55
#  1   2014   40    4       =>       4      2014   40
#  2   2013   84    7                7      2013   84
#  3   2014   31    10               10     2014   31
1
0

agregar una columna de índice pandas

import numpy as np
import pandas as pd
df = pd.DataFrame({'month': [2, 5, 8, 10],
                   'year': [2017, 2019, 2018, 2019],
                   'sale': [60, 45, 90, 36]})
df.set_index('month')
0
0

los pandas df convierten el conjunto de columna de índice

df.reset_index(inplace=True)
df = df.rename(columns = {'index':'new column name'})
0
0

cómo configurar pandas índice

# assignment copy
df = df.set_index('month')

# or inplace
df.set_index('month', inplace=True)

#      year   sale  month            month  year   sale
#  0   2012   55    1                1      2012   55
#  1   2014   40    4       =>       4      2014   40
#  2   2013   84    7                7      2013   84
#  3   2014   31    10               10     2014   31
0
0

str reemplazar pandas

>>> pd.Series(['foo', 'fuz', np.nan]).str.replace('f.', 'ba', regex=True)
0    bao
1    baz
2    NaN
dtype: object

Páginas relacionadas

Páginas de ejemplo relacionadas

En otros idiomas

Esta página está en otros idiomas

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................