4 ms·
What kind of syntax is var['string'] in these examples? Haven't really used python for anything and I'm just wondering, since it looks like an array or map, bu
by NightlyDev 8y ago
What kind of syntax is var['string'] in these examples?
Haven't really used python for anything and I'm just wondering, since it looks like an array or map, but clearly seems to have some logic behind it as it seems to reference the specified column at each row. What is this functionality, something that's built in to python or use of some sort of magic functions?
- xapata 8y agoIt's key-lookup syntax, like for a dict (map or hashmap in other languages). A Pandas DataFrame can be thought of as a dict of columns.
- cgriswald 8y agovar['string'] means get the item of object var with key 'string'. Any Python class can define the magic method __getitem__ to define the behavior of/overload the [] operator.
- NightlyDev 8y agoThanks! Didn't know python had magic functions so I was really confused.