I have the following dataframe:
address.state address.town dates
0 MI Dearborn None
1 CA Los Angeles [2014-01-01, 2015-01-01]
How would I get a list of all values for the column, splitting up if there's ever a list value. For example:
>>> df['address.state']
['MI', 'CA'] # length of 2
>>> df['dates']
[None, '2014-01-01', '2015-01-01'] # length of 3
How would I do this in a generalized way if any of the values in the df columns has a list field?
Currently what I'm doing is:
_values = []
for _val in df.iloc[:,col_index]:
if not isinstance(_val, list):
_values.append(_val)
else:
_values.extend(_val)
>>> _values
['2014-01-01', '2015-01-01', None]
Is there a better way to do this though, perhaps directly in pandas?