Skip to content

Instantly share code, notes, and snippets.

@noskill
Last active February 26, 2020 14:22
Show Gist options
  • Save noskill/b5eb428e5632f093c8b57ec997c640c5 to your computer and use it in GitHub Desktop.
Save noskill/b5eb428e5632f093c8b57ec997c640c5 to your computer and use it in GitHub Desktop.
multiindex dataframe in pandas
import pandas as pd
from pandas.core.indexes.api import ensure_index_from_sequences
col_dict = {'FrameId':(0,), 'Id':(1,), 'X': (321.89,), 'Y': (381.81,), 'Width': (39.45,), 'Height': (49.45,), 'ClassId': (-1,), 'Visibility': (-1,), 'unused': (-1,)}
names = ['X', 'Y', 'Width', 'Height', 'Confidence', 'ClassId', 'Visibility', 'unused']
arrays = col_dict['FrameId'], col_dict['Id']
index = ensure_index_from_sequences(arrays, names=('FrameId', 'Id'))
dfnew = pd.DataFrame(col_dict, columns=names, index=index)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment