<jupyter_start><jupyter_text>pandas Data> <NAME>  > Laboratory of Biomechanics and Motor Control ([http://demotu.org/](http://demotu.org/))  > Federal University of ABC, Brazil<jupyter_code>import numpy as np
import pandas as pd
%matplotlib notebook
# tk qt notebook inline ipympl
import matplotlib as mpl
import matplotlib.pyplot as plt
import sys, os
sys.path.insert(1, r'./../functions')
path2 = r'./../../../X/Clau/'
name = 'WBDS01walkT06mkr.txt'
fname = os.path.join(path2, name)<jupyter_output><empty_output><jupyter_text>pandas with one index<jupyter_code>df = pd.read_csv(fname, sep='\t', header=0, index_col=0, dtype=np.float64, engine='c')
df.columns = df.columns.str.replace('\.', '')
df.head()
ax = df.plot(y='RASISX', figsize=(8, 3), title='A plot of kinematics')
ax.set_ylabel('Position [mm]')
plt.tight_layout(pad=0, h_pad=0, rect=[0, 0, 1, .95])
def plot_widget(df):
    """general plot widget of a pandas dataframe
    """
    
    from ipywidgets import widgets
    
    col_w = widgets.SelectMultiple(options=df.columns,
                                   value=[df.columns[0]],
                                   description='Column')
    clear_w = widgets.Checkbox(value=True,
                              description='Clear axis')
    container = widgets.HBox(children=[col_w, clear_w])
    display(container)
    
    fig, ax = plt.subplots(1, 1, figsize=(9, 4))
    if col_w.value:
        df.plot(y=col_w.value[0], ax=ax)  
    plt.tight_layout()
    plt.show()
    
    def plot(change):
        if clear_w.value:
            ax.clear()
        for c in col_w.value:
            df.plot(y=c, ax=ax)

    col_w.observe(plot, names='value')
plot_widget(df)<jupyter_output><empty_output><jupyter_text>pandas multiindexData with hierarchical column index ([multiindex](http://pandas.pydata.org/pandas-docs/stable/advanced.htmlcreating-a-multiindex-hierarchical-index-object)) where columns have multiple levels.<jupyter_code>df = pd.read_csv(fname, sep='\t', header=0, index_col=0, dtype=np.float64, engine='c')
# format columns as multindexes and relabel them
cols = [s[:-1] for s in df.columns.str.replace('\.', '')]
df.columns = [cols, list('XYZ')*int(df.shape[1]/3)]
df.columns.set_names(names=['Marker', 'Coordinate'], level=[0, 1], inplace=True)
#df = df.swaplevel(0, 1, axis=1)  # for 'Coordinate' to go first
df.head()
df['RASIS'].head()
# df.RASIS.head()
df.RASIS.X.head()
# df['RASIS']['X'].head()
df.xs('X', level='Coordinate', axis=1).head()
df.loc[:, (slice(None), 'X')].head()
df.swaplevel(0, 1, axis=1).head()  # for 'Coordinate' to go first
ax = df.plot(y=('RASIS', 'X'), subplots=True, figsize=(8, 2), rot=0)
ax = df.plot(y='RASIS', subplots=True, sharex=True, figsize=(8, 4), rot=0,
             title='A plot of kinematics')
plt.tight_layout(pad=0, h_pad=0, rect=[0, 0, 1, .95])
values = df.reset_index(drop=False).values
values[0, :5]
df.head()
x = df.swaplevel(0, 1, axis=1)
x2 = x.unstack(level=-1)
x2.head()
x.head()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17780748663101603, 'fraction_numerical': 0.021056149732620322, 'mean_word_length': 3.8352180936995155, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '56896', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 1168, 'n_tokens_neox': 1125, 'n_words': 231, 'path': 'notebooks/pandas_data.ipynb', 'repo_name': 'gbiomech/BMC', 'size': '2999'}