slzdevsnp
8/14/2019 - 3:26 PM

[pandas_index] #index #reset_index #set_index

[pandas_index] #index #reset_index #set_index

import pandas as pd
import numpy as np


####################
#   loc, iloc, ix #
####################
data = pd.Series(['a', 'b', 'c'], index=[1, 3, 5])

#git top 2 elements
data.iloc[0:2]

## specify explici values of index
data.loc[[1,3]]

data.loc[1:3]

####################
#   moving columns #
#  to/from index   #
####################

data = pd.Series([0.25, 0.5, 0.75, 1.0],
                 index=['a', 'b', 'c', 'd'])

df=pd.DataFrame(data,columns=['val0'])

#put index, multiindex values into columns
df.reset_index(inplace=True)

nvals=10
dt_rng = pd.date_range('2019-01-01', periods=nvals,
                           freq='1D',)
df = pd.DataFrame(dt_rng, columns=['ts'])
df['rv1'] = np.random.randn(nvals, 1)
df['rv2'] = np.random.randn(nvals, 1)
#setting a column to index
df = df.set_index('ts',inplace=True)