Pythonic way für die Berechnung der Länge der Listen in pandas dataframe Spalte

Ich habe einen dataframe, wie diese:

                                                    CreationDate
2013-12-22 15:25:02                  [ubuntu, mac-osx, syslinux]
2009-12-14 14:29:32  [ubuntu, mod-rewrite, laconica, apache-2.2]
2013-12-22 15:42:00               [ubuntu, nat, squid, mikrotik]

Ich bin Berechnung der Länge der Listen in der CreationDate Spalte und eine neue Length Spalte wie folgt:

df['Length'] = df.CreationDate.apply(lambda x: len(x))

Gibt mir dies:

                                                    CreationDate  Length
2013-12-22 15:25:02                  [ubuntu, mac-osx, syslinux]       3
2009-12-14 14:29:32  [ubuntu, mod-rewrite, laconica, apache-2.2]       4
2013-12-22 15:42:00               [ubuntu, nat, squid, mikrotik]       4

Gibt es eine mehr pythonic Weg, dies zu tun?

InformationsquelleAutor MYGz | 2016-12-27
Schreibe einen Kommentar