Tricky : ‘dict’ object is not callable

What you’ve run into is called “shadowing”. You’ve created an object in some namespace (either the global namespace of your module, or the local namespace of a function) that has the same name as a the builtin dict type. This prevents you from accessing the builtin dict in the usual way. You can still get to it, with a bit more … Read more

DataFrame constructor not properly called

The pd.DataFrame constructor does not accept a dictionary view as data. You can convert to list instead. Here’s a minimal example: The docs do suggest this: data : numpy ndarray (structured or homogeneous), dict, or DataFrame Equivalently, you can use pd.DataFrame.from_dict, which accepts a dictionary directly:

How can I remove a key from a Python dictionary?

To delete a key regardless of whether it is in the dictionary, use the two-argument form of dict.pop(): This will return my_dict[key] if key exists in the dictionary, and None otherwise. If the second parameter is not specified (i.e. my_dict.pop(‘key’)) and key does not exist, a KeyError is raised. To delete a key that is guaranteed to exist, you can also use: This will raise a KeyError if the … Read more

When is del useful in Python?

Firstly, you can del other things besides local variables Both of which should be clearly useful. Secondly, using del on a local variable makes the intent clearer. Compare: to I know in the case of del foo that the intent is to remove the variable from scope. It’s not clear that foo = None is doing that. If somebody just assigned foo … Read more