python - using reserved words in column names in pandas -


using reserved names column names in pandas not provide error or warning message. code runs through without doing anything. there way turn on kind of warning prevent use of reserved words column names?

mwe:

import pandas pd  index_names = ['1','2','3'] col_names = ['median','a']  df = pd.dataframe(index = index_names, columns = col_names) df.fillna(0, inplace = true) df.ix[1].a = 12 df.ix[1].median = 12 print df 

output:

 median    1    0    0 2    0    12 3    0    0 

in python, unlike other languages there isn't concept of variables. python has names point objects.

since python not strict typed (unlike java or c++ example), have flexibility assign names other objects, names point functions (since functions are, else, object).

although extremely flexible (it allows overwrite functionality of objects overwriting names of functions), mean python not warn if try impacts built-in name. called shadowing.

it 1 of tradeoffs of having flexible type system, , python programmers need aware of.

here canonical example:

>>> type(id) <type 'builtin_function_or_method'> >>> id(4) 10677280 >>> id = 5 >>> type(id) <type 'int'> >>> id(5) traceback (most recent call last):   file "<stdin>", line 1, in <module> typeerror: 'int' object not callable 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -