Skip to content

Instantly share code, notes, and snippets.

@zverbatim
Last active July 28, 2017 13:39
Show Gist options
  • Save zverbatim/86db71ffeb30941e890a68a961d83f2e to your computer and use it in GitHub Desktop.
Save zverbatim/86db71ffeb30941e890a68a961d83f2e to your computer and use it in GitHub Desktop.
# filter an array
# version 1
areas = ["hallway", 11.25, "kitchen", 18.0, "living room", 20.0, "bedroom", 10.75, "bathroom", 9.50]
valid = lambda x: type(x) == float
sum = sum( filter (valid, areas) )
# version 2
out = [a for a in areas if type(a) != str]
# pandas from lists
import pandas as pd
list_keys = ['Country', 'Total']
list_values = [['US', 'Mexico', 'Canada'], [1000, 500, 400]]
zipped = list(zip(list_keys, list_values))
data = dict(zipped)
df = pd.(data)
print(df.head())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment