Tag Archives: python example

How to get odd and even numbers from a list in Python

Hits: 16  How to get odd and even numbers from a list in Python In this coding example, we learn how to find odd and even numbers from a list using Python program. Code Example:   Outcomes:   Python Example for Beginners Special 95% discount 2000+ Applied Machine Learning & Data Science Recipes Portfolio Projects …

Python Example – The most simplest python program to create a QR code

Hits: 8 The most simplest python program to create a QR code In this coding example,  we showed how to generate a QR code using Python package called pyqrcode. It is a very simple example.     Result   Python Example for Beginners Special 95% discount 2000+ Applied Machine Learning & Data Science Recipes Portfolio …

How to get prime and composite numbers in Python

Hits: 1 Python program to get prime and composite numbers startNumber = 1 endNumber = 20 prime = [] composite = [] for i in range(startNumber,endNumber): for p in range(2, i): if (i % p)==0: composite.append(i) break else: prime.append(i) print(“prime: “,prime) print(“composite: “,composite) /* Output */ prime: [1, 2, 3, 5, 7, 11, 13, 17, …

Data Viz in Python – Color Palettes in Seaborn

Hits: 1 Color Palettes in Seaborn Preliminaries import pandas as pd %matplotlib inline import matplotlib.pyplot as plt import seaborn as sns data = {‘date’: [‘2014-05-01 18:47:05.069722’, ‘2014-05-01 18:47:05.119994’, ‘2014-05-02 18:47:05.178768’, ‘2014-05-02 18:47:05.230071’, ‘2014-05-02 18:47:05.230071’, ‘2014-05-02 18:47:05.280592’, ‘2014-05-03 18:47:05.332662’, ‘2014-05-03 18:47:05.385109’, ‘2014-05-04 18:47:05.436523’, ‘2014-05-04 18:47:05.486877’], ‘deaths_regiment_1’: [34, 43, 14, 15, 15, 14, 31, 25, 62, 41], …

Data Viz in Python – Bar Plot In MatPlotLib

Hits: 5 Back To Back Bar Plot In MatPlotLib Preliminaries %matplotlib inline import pandas as pd import matplotlib.pyplot as plt import numpy as np Create dataframe raw_data = {‘first_name’: [‘Jason’, ‘Molly’, ‘Tina’, ‘Jake’, ‘Amy’], ‘pre_score’: [4, 24, 31, 2, 3], ‘mid_score’: [25, 94, 57, 62, 70], ‘post_score’: [5, 43, 23, 23, 51]} df = pd.DataFrame(raw_data, …

Data Wrangling in Python – Pandas Time Series Basics

Hits: 4 Pandas Time Series Basics Import modules from datetime import datetime import pandas as pd %matplotlib inline import matplotlib.pyplot as pyplot Create a dataframe data = {‘date’: [‘2014-05-01 18:47:05.069722’, ‘2014-05-01 18:47:05.119994’, ‘2014-05-02 18:47:05.178768’, ‘2014-05-02 18:47:05.230071’, ‘2014-05-02 18:47:05.230071’, ‘2014-05-02 18:47:05.280592’, ‘2014-05-03 18:47:05.332662’, ‘2014-05-03 18:47:05.385109’, ‘2014-05-04 18:47:05.436523’, ‘2014-05-04 18:47:05.486877’], ‘battle_deaths’: [34, 25, 26, 15, 15, 14, …

Data Wrangling in Python – How to Sort Rows In pandas Dataframes

Hits: 5 Sorting Rows In pandas Dataframes import modules import pandas as pd Create dataframe data = {‘name’: [‘Jason’, ‘Molly’, ‘Tina’, ‘Jake’, ‘Amy’], ‘year’: [2012, 2012, 2013, 2014, 2014], ‘reports’: [1, 2, 1, 2, 3], ‘coverage’: [2, 2, 3, 3, 3]} df = pd.DataFrame(data, index = [‘Cochice’, ‘Pima’, ‘Santa Cruz’, ‘Maricopa’, ‘Yuma’]) df coverage name …

Learn Python By Example – Example Dataframes In pandas

Hits: 7 Simple Example Dataframes In pandas import modules import pandas as pd Create dataframe raw_data = {‘first_name’: [‘Jason’, ‘Molly’, ‘Tina’, ‘Jake’, ‘Amy’], ‘last_name’: [‘Miller’, ‘Jacobson’, ‘Ali’, ‘Milner’, ‘Cooze’], ‘age’: [42, 52, 36, 24, 73], ‘preTestScore’: [4, 24, 31, 2, 3], ‘postTestScore’: [25, 94, 57, 62, 70]} df = pd.DataFrame(raw_data, columns = [‘first_name’, ‘last_name’, ‘age’, …

Data Wrangling in Python – How to Select pandas DataFrame Rows Based On Conditions

Hits: 6 Selecting pandas DataFrame Rows Based On Conditions Preliminaries /* Import modules */ import pandas as pd import numpy as np /* Create a dataframe */ raw_data = {‘first_name’: [‘Jason’, ‘Molly’, np.nan, np.nan, np.nan], ‘nationality’: [‘USA’, ‘USA’, ‘France’, ‘UK’, ‘UK’], ‘age’: [42, 52, 36, 24, 70]} df = pd.DataFrame(raw_data, columns = [‘first_name’, ‘nationality’, ‘age’]) …

Data Wrangling in Python – How to Select Rows With Multiple Filters

Hits: 4 Select Rows With Multiple Filters /* import pandas as pd */ import pandas as pd /* Create an example dataframe */ data = {‘name’: [‘A’, ‘B’, ‘C’, ‘D’, ‘E’], ‘score’: [1,2,3,4,5]} df = pd.DataFrame(data) df name score 0 A 1 1 B 2 2 C 3 3 D 4 4 E 5 /* …

Data Wrangling in Python – How to Select Rows With A Certain Value

Hits: 5 Select Rows With A Certain Value import pandas as pd /* Create an example dataframe */ data = {‘name’: [‘Jason’, ‘Molly’], ‘country’: [[‘Syria’, ‘Lebanon’],[‘Spain’, ‘Morocco’]]} df = pd.DataFrame(data) df country name 0 Syria,LebanonSyria,Lebanon Jason 1 Spain,MoroccoSpain,Morocco Molly df[df[‘country’].map(lambda country: ‘Syria’ in country)] country name 0 Syria,LebanonSyria,Lebanon Jason Python Example for Beginners Special 95% …

Data Wrangling in Python – How to Search A pandas Column For A Value

Hits: 3 Search A pandas Column For A Value /* Import modules */ import pandas as pd raw_data = {‘first_name’: [‘Jason’, ‘Jason’, ‘Tina’, ‘Jake’, ‘Amy’], ‘last_name’: [‘Miller’, ‘Miller’, ‘Ali’, ‘Milner’, ‘Cooze’], ‘age’: [42, 42, 36, 24, 73], ‘preTestScore’: [4, 4, 31, 2, 3], ‘postTestScore’: [25, 25, 57, 62, 70]} df = pd.DataFrame(raw_data, columns = [‘first_name’, …

Data Wrangling in Python – How to Save A pandas Dataframe As A CSV

Hits: 5 Saving A pandas Dataframe As A CSV import modules import pandas as pd Create dataframe raw_data = {‘first_name’: [‘Jason’, ‘Molly’, ‘Tina’, ‘Jake’, ‘Amy’], ‘last_name’: [‘Miller’, ‘Jacobson’, ‘Ali’, ‘Milner’, ‘Cooze’], ‘age’: [42, 52, 36, 24, 73], ‘preTestScore’: [4, 24, 31, 2, 3], ‘postTestScore’: [25, 94, 57, 62, 70]} df = pd.DataFrame(raw_data, columns = [‘first_name’, …

Data Wrangling in Python – How to Replace Values In pandas

Hits: 4 Replacing Values In pandas import modules import pandas as pd import numpy as np Create dataframe raw_data = {‘first_name’: [‘Jason’, ‘Molly’, ‘Tina’, ‘Jake’, ‘Amy’], ‘last_name’: [‘Miller’, ‘Jacobson’, ‘Ali’, ‘Milner’, ‘Cooze’], ‘age’: [42, 52, 36, 24, 73], ‘preTestScore’: [-999, -999, -999, 2, 1], ‘postTestScore’: [2, 2, -999, 2, -999]} df = pd.DataFrame(raw_data, columns = …