IPython Notebook and Pandas AutoComplete

I noticed that if I typed df.column_name(), I can autofill a column_nametab in an IPython laptop.

Now the correct syntax for doing something for the column will be df['column_name']where I cannot autocomplete (I assume this is a string?). Is there any other notation or a way to simply enter column names. I'm just looking for a solution that would allow me to insert autocomplete column name in this df['column_name'].

+3
source share
2 answers

I found the following method for me. It basically creates namedtuplecontaining the names of all the variables in the data frame as strings.

, , 2 , "variable_1" "variable_2":

from collections import namedtuple
from pandas import DataFrame
import numpy as np

df = DataFrame({'variable_1':np.arange(5),'variable_2':np.arange(5)})

"var":

def ntuples():
    list_of_names = df.columns.values
    list_of_names_dict = {x:x for x in list_of_names}

    Varnames = namedtuple('Varnames', list_of_names) 
    return Varnames(**list_of_names_dict)

var = ntuples()

, var. Tab, df. var.variable_1 'variable_1'. : df[var.variable_1].

, , , . namedtuple "var", , ntuples(), .

+3

, , csv/txt, , ...

names = ['col_1', 'col_2', 'col_3']

..... ...

import pandas as pd
data = pd.read_csv('./some_file.txt', header = True, delimiter = '\t', names = names)

, ...

new_thing = data[names[1]]

, "", , , , "name" . , , .

+1

All Articles