Samantha Jackson (@Cranksss) header
Samantha Jackson (@Cranksss) profile picture

Feminist ✌🏼️Animal Lover 🐶 Sun Worshiper ☀️ Dance Enthusiast 💃🏼 Actuary 🤓 Data Science Analyst 📊 NYC ➡️ SD

San Diego, CA
Joined September 2010
Photo by Samantha Jackson (@Cranksss)Photo by Samantha Jackson (@Cranksss)Photo by Samantha Jackson (@Cranksss)
Samantha Jackson retweeted
🐼🤹‍♂️ pandas trick #77: Want to combine the smaller categories in a Series into a single category called "Other"? 1. Save the index of the largest values of value_counts() 2. Use where() to replace all other values with "Other" See example 👇 #Python #DataScience #pandastricks
9
56
7
307
Samantha Jackson retweeted
🐼🤹‍♂️ pandas trick: Want to calculate the difference between each row and the previous row? Use df.col_name.diff() Want to calculate the percentage change instead? Use df.col_name.pct_change() See example 👇 #Python #DataScience #pandas #pandastricks
2
22
145
Samantha Jackson retweeted
🐼🤹‍♂️ pandas trick: Need to refer to a local variable within a query() string? Just prefix it with the @ symbol! See example 👇 #Python #DataScience #pandas #pandastricks
2
23
1
140
Samantha Jackson retweeted
🐼🤹‍♂️ pandas trick: "loc" selects by label, and "iloc" selects by position. But what if you need to select by label *and* position? You can still use loc or iloc! See example 👇 P.S. Don't use "ix", it has been deprecated since 2017. #Python #DataScience #pandas #pandastricks
7
20
2
140
Samantha Jackson retweeted
🐼🤹 pandas trick: There are many display options you can change: max_rows max_columns max_colwidth precision date_dayfirst date_yearfirst How to use: pd.set_option('display.max_rows', 80) pd.reset_option('display.max_rows') See all: pd.describe_option() #Python #pandastricks
16
105
Samantha Jackson retweeted
🐼🤹‍♂️ pandas trick: Need to convert a column from continuous to categorical? Use cut(): df['age_groups'] = pd.cut(df.age, bins=[0, 18, 65, 99], labels=['child', 'adult', 'elderly']) 0 to 18 ➡️ 'child' 18 to 65 ➡️ 'adult' 65 to 99 ➡️ 'elderly' #Python #pandas #pandastricks
15
117
7
619
Samantha Jackson retweeted
🐼🤹‍♂️ pandas trick: Calculate % of missing values in each column: df.isna().mean() Drop columns with any missing values: df.dropna(axis='columns') Drop columns in which more than 10% of values are missing: df.dropna(thresh=len(df)*0.9, axis='columns') #Python #pandastricks
3
19
79
Samantha Jackson retweeted
🐼🤹‍♂️ pandas trick: Numbers stored as strings? Try astype(): df.astype({'col1':'int', 'col2':'float'}) But it will fail if you have any invalid input. Better way: df.apply(pd.to_numeric, errors='coerce') Converts invalid input to NaN 🎉 #Python #pandastricks
1
18
84
Samantha Jackson retweeted
How to turn a column of dictionaries into individual columns in Pandas. stackoverflow.com/a/38231651…
1
6
25
Samantha Jackson retweeted
🐼🤹‍♂️ pandas trick: Select columns by data type: df.select_dtypes(include='number') df.select_dtypes(include=['number', 'category', 'object']) df.select_dtypes(exclude=['datetime', 'timedelta']) #Python #DataScience #pandas #pandastricks
1
17
71
Samantha Jackson retweeted
🐼🤹‍♂️ pandas trick: Filter DataFrame by multiple OR conditions: df[(df.color == 'red') | (df.color == 'green') | (df.color == 'blue')] Shorter way: df[df.color.isin(['red', 'green', 'blue'])] Invert the filter: df[~df.color.isin(['red', 'green', 'blue'])] #Python #pandastricks
5
18
2
99
We’ll soon know the exact air pollution from every power plant in the world. That’s huge. vox.com/energy-and-environme… via @voxdotcom
1
Femtech Startups Are Finally Innovating for Menopause by Zara Stone medium.com/p/femtech-startup…