Replace Excel If Function with Python Pandas

35 Просмотры
Издатель
Simple conditional logic in excel can get very complex whenever you start having multiple conditionals. With only one line to include your conditionals, or having to write VBA, Excel isn't as user friendly for these operations.

Sample Data
https://github.com/Derrick-Sherrill/DerrickSherrill.com/blob/master/Sample%20Data/sample_scores.xlsx

Python + Pandas makes these operations so much easier!

Kite helps fund the channel, thanks for checking them out and supporting me --
⭐ Kite is a free AI-powered coding assistant that will help you code faster and smarter. The Kite plugin integrates with all the top editors and IDEs to give you smart completions and documentation while you’re typing.

#Python #Excel #Automation

Merch Store --
https://derricksherrill.store/
Support the Channel on Patreon --
https://www.patreon.com/join/derricksherrill
Join The Socials --
Reddit - https://www.reddit.com/r/CodeWithDerrick/
FB - https://www.facebook.com/CodeWithDerrick/
Insta - https://www.instagram.com/codewithderrick/
Twitter - https://twitter.com/codewithderrick
LinkedIn - https://www.linkedin.com/in/derricksherrill/
GitHub - https://github.com/Derrick-Sherrill
*****************************************************************
Full code from the video:

https://github.com/Derrick-Sherrill/DerrickSherrill.com/blob/master/replace_excel_if.py

import numpy as np
import pandas as pd

scores_df = pd.read_excel('sample_scores.xlsx')
#print(scores_df)

scores_df['average'] = scores_df.mean(axis=1)

#scores_df['Pass/Fail'] = np.where(scores_df['average'] #greater than 60, 'Pass', 'Fail')
#print(scores_df)

conditions = [
# "Angled Brackets aren't allowed" in YouTube Descriptions. :(
]
results = ['A', 'B', 'C', 'D', 'F']

scores_df['Letter Grade'] = np.select(conditions, results)
#print(scores_df)

scores_df['Pass/Fail'] = ['Pass' if x #greater than 60 else 'fail' for x in scores_df['average']]
print(scores_df)

Packages (& Versions) used in this video:
Pandas 1.1.3
NumPy

*****************************************************************
Code from this tutorial and all my others can be found on my GitHub:
https://github.com/Derrick-Sherrill/DerrickSherrill.com

Check out my website:
https://www.derricksherrill.com/

If you liked the video - please hit the like button. It means more than you know. Thanks for watching and thank you for all your support!!

--- Channel FAQ --

What text editor do you use?
Atom - https://atom.io/

What Equipment do you use to film videos?
https://www.amazon.com/shop/derricksherrill

What editing software do you use?
Adobe CC - https://www.adobe.com/creativecloud.html
Premiere Pro for video editing
Photoshop for images
After Effects for animations

Do I have any courses available?
Yes & always working on more!
https://www.udemy.com/user/derrick-sherrill-2/

Where do I get my music?
I get all my music from the copyright free Youtube audio library
https://www.youtube.com/audiolibrary/music?nv=1

Let me know if there's anything else you want answered!

-------------------------

Always looking for suggestions on what video to make next -- leave me a comment with your project! Happy Coding!
Категория
Новости 3D Печати
Комментариев нет.