Skip to content
Advertisement

Tag: null

Python: Safe dictionary access with lists?

Is there an exception free way to access values from a dictionary containing lists. For example, if I have: How do I access the path data[‘object_1’][‘object_2’][‘list’][0][‘property’] safely(i.e. return some default value if not possible to access without throwing error)? I am trying to avoid wrapping these in try-except’s. I have seen the reduce based approach but it doesn’t take into

Python pandas apply function if a column value is not NULL

I have a dataframe (in Python 2.7, pandas 0.15.0): I want to apply a simple function for rows that does not contain NULL values in a specific column. My function is as simple as possible: And my apply code is the following: It works perfectly. If I want to check column ‘B’ for NULL values the pd.notnull() works perfectly as

What is a ‘NoneType’ object?

I’m getting this error when I run my python script: I’m pretty sure the ‘str’ means string, but I dont know what a ‘NoneType’ object is. My script craps out on the second line, I know the first one works because the commands from that line are in my asa as I would expect. At first I thought it may

Advertisement