This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| df = pd.DataFrame({ | |
| 'Name': ['Nik', 'Kate', 'Evan'], | |
| 'Location': ['Toronto, ON', 'Atlanta, GA', 'Portland, OR'], | |
| 'Total': [99.99, 125.65, 33.43] | |
| }) | |
| df['Over 100'] = ['Yes' if Total > 100 else 'No' for Total in df['Total']] | |
| df[['City', 'State']] = df['Location'].str.split(', ', expand=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Using text-to-columns in Pandas | |
| import pandas as pd | |
| df = pd.DataFrame({ | |
| 'Name': ['Nik', 'Kate', 'Evan'], | |
| 'Location': ['Toronto, ON', 'Atlanta, GA', 'Portland, OR'], | |
| 'Total': [99.99, 125.65, 33.43] | |
| }) | |
| df['Over 100'] = ['Yes' if Total > 100 else 'No' for Total in df['Total']] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Using if Statements in Python | |
| import pandas as pd | |
| df = pd.DataFrame({ | |
| 'Name': ['Nik', 'Kate', 'Evan'], | |
| 'Location': ['Toronto, ON', 'Atlanta, GA', 'Portland, OR'], | |
| 'Total': [99.99, 125.65, 33.43] | |
| }) | |
| df['Over 100'] = ['Yes' if Total > 100 else 'No' for Total in df['Total']] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Loading a Sample Pandas DataFrame | |
| import pandas as pd | |
| df = pd.DataFrame({ | |
| 'Name': ['Nik', 'Kate', 'Evan'], | |
| 'Location': ['Toronto, ON', 'Atlanta, GA', 'Portland, OR'], | |
| 'Total': [99.99, 125.65, 33.43] | |
| }) | |
| print(df) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "If Name == Main": { | |
| "prefix": "ifn", | |
| "body": [ | |
| "if __name__ == '__main__':", | |
| " $0" | |
| ], | |
| "description": "If Name == Main" | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "Filter a Pandas DataFrame": { | |
| "prefix": "pf", | |
| "body": [ | |
| "${1:df} = ${1:df}[${1:df}['${2:Column}'] ${3|==, >, >=, <, <=, !=|} ${4:Filter}] " | |
| ], | |
| "description": "Filter a Pandas DataFrame" | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "Modify a Pandas Column": { | |
| "prefix": "pdc", | |
| "body": [ | |
| "${1:df_name}['${2:col_name}'] = ${1:df_name}['${2:col_name}'].$0" | |
| ], | |
| "description": "Modifies a Pandas Column" | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| // "Print to console": { | |
| // "prefix": "log", | |
| // "body": [ | |
| // "console.log('$1');", | |
| // "$2" | |
| // ], | |
| // "description": "Log output to console" | |
| // } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Reading Multiple Columns As Date Time | |
| import pandas as pd | |
| df = pd.read_excel( | |
| 'Pandas_read_files_tips.xlsx', | |
| parse_dates={'Date': ['Month', 'Day', 'Year']} | |
| ) | |
| print(df) | |
| # Returns: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| import os | |
| # Create list of files | |
| file_path = '/Desktop/Files/' | |
| files = [os.path.join(file_path, file) for file in os.listdir(file_path)] | |
| # Join DataFrames Using pd.concat() | |
| df = pd.concat([pd.read_excel(file) for file in files], ignore_index=True) | |
| print(df.head()) |
NewerOlder