I can't understand why this snippet of code:
df = PA.DataFrame()
[df.append(aFunction(x)) for x in aPandaSeries]
does not give me the same DataFrame (df) as:
df = PA.DataFrame()
for x in xrange(len(aPandaSeries)):
df = df.append(aFunction(aPandaSeries[x]))
I am trying to pythonise the second section by using the first section, but df has far fewer rows in the former than the latter.
A couple of things...
.append() method returns None. So df = df.append() will set df to None value.
List comprehensions are useful to filter or process a list of values, so you generally wouldn't use .append() with a list comprehension. It makes more sense to rewrite the 2nd line in first snippet as:
for x in aPandaSeries: df.append(aFunction(x))
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments