Tag Archives: Python for Citizen Data Scientist

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 implement K-Nearest Neighbors Algorithm in Python and Scikit-Learn

Hits: 2  How to implement K-Nearest Neighbors Algorithm in Python and Scikit-Learn The K-nearest neighbors (KNN) algorithm is a type of supervised machine learning algorithms. KNN is extremely easy to implement in its most basic form, and yet performs quite complex classification tasks. It is a lazy learning algorithm since it doesn’t have a specialized training phase. …

Introduction to Neural Networks with Scikit-Learn in Python

Hits: 1 Introduction to Neural Networks with Scikit-Learn in Python What is a Neural Network? Humans have an ability to identify patterns within the accessible information with an astonishingly high degree of accuracy. Whenever you see a car or a bicycle you can immediately recognize what they are. This is because we have learned over …

How to do K-Means Clustering with Scikit-Learn in Python

Hits: 5 How to do K-Means Clustering with Scikit-Learn in Python Introduction K-means clustering is one of the most widely used unsupervised machine learning algorithms that forms clusters of data based on the similarity between data instances. For this particular algorithm to work, the number of clusters has to be defined beforehand. The K in …

TensorFlow Neural Network Tutorial in Python

Hits: 4  TensorFlow Neural Network Tutorial in Python TensorFlow is an open-source library for machine learning applications. It’s the Google Brain’s second generation system, after replacing the close-sourced DistBelief, and is used by Google for both research and production applications. TensorFlow applications can be written in a few languages: Python, Go, Java and C. This …

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 Rows When Columns Contain Certain Values

Hits: 6 Select Rows When Columns Contain Certain Values Preliminaries /* Import modules */ import pandas as pd /* Set ipython’s max row display */ pd.set_option(‘display.max_row’, 1000) /* Set iPython’s max column width to 50 */ pd.set_option(‘display.max_columns’, 50) Create an example dataframe /* Create an example dataframe */ data = {‘name’: [‘Jason’, ‘Molly’, ‘Tina’, ‘Jake’, …

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 Find Hierarchical Data In pandas

Hits: 2 Hierarchical Data In pandas /* import modules */ import pandas as pd /* Create dataframe */ raw_data = {‘regiment’: [‘Nighthawks’, ‘Nighthawks’, ‘Nighthawks’, ‘Nighthawks’, ‘Dragoons’, ‘Dragoons’, ‘Dragoons’, ‘Dragoons’, ‘Scouts’, ‘Scouts’, ‘Scouts’, ‘Scouts’], ‘company’: [‘1st’, ‘1st’, ‘2nd’, ‘2nd’, ‘1st’, ‘1st’, ‘2nd’, ‘2nd’,’1st’, ‘1st’, ‘2nd’, ‘2nd’], ‘name’: [‘Miller’, ‘Jacobson’, ‘Ali’, ‘Milner’, ‘Cooze’, ‘Jacon’, ‘Ryaner’, ‘Sone’, ‘Sloan’, …

Data Wrangling in Python – How to Create A pandas Column With A For Loop

Hits: 4 Grouping Rows In pandas /* Import modules */ import pandas as pd /* Example dataframe */ raw_data = {‘regiment’: [‘Nighthawks’, ‘Nighthawks’, ‘Nighthawks’, ‘Nighthawks’, ‘Dragoons’, ‘Dragoons’, ‘Dragoons’, ‘Dragoons’, ‘Scouts’, ‘Scouts’, ‘Scouts’, ‘Scouts’], ‘company’: [‘1st’, ‘1st’, ‘2nd’, ‘2nd’, ‘1st’, ‘1st’, ‘2nd’, ‘2nd’,’1st’, ‘1st’, ‘2nd’, ‘2nd’], ‘name’: [‘Miller’, ‘Jacobson’, ‘Ali’, ‘Milner’, ‘Cooze’, ‘Jacon’, ‘Ryaner’, ‘Sone’, ‘Sloan’, …

Data Wrangling in Python – How to Geolocate A City Or Country

Hits: 7 Geolocate A City Or Country This tutorial creates a function that attempts to take a city and country and return its latitude and longitude. But when the city is unavailable (which is often be the case), the returns the latitude and longitude of the center of the country. Preliminaries from geopy.geocoders import Nominatim …

Data Wrangling in Python – How to Filter pandas Dataframes

Hits: 4 Filter pandas Dataframes Import modules import pandas as pd Create Dataframe data = {‘name’: [‘Jason’, ‘Molly’, ‘Tina’, ‘Jake’, ‘Amy’], ‘year’: [2012, 2012, 2013, 2014, 2014], ‘reports’: [4, 24, 31, 2, 3], ‘coverage’: [25, 94, 57, 62, 70]} df = pd.DataFrame(data, index = [‘Cochice’, ‘Pima’, ‘Santa Cruz’, ‘Maricopa’, ‘Yuma’]) df coverage name reports year …

Data Wrangling in Python – How to Expand Cells Containing Lists Into Their Own Variables In Pandas

Hits: 6 Expand Cells Containing Lists Into Their Own Variables In Pandas /* import pandas */ import pandas as pd /* create a dataset */ raw_data = {‘score’: [1,2,3], ‘tags’: [[‘apple’,’pear’,’guava’],[‘truck’,’car’,’plane’],[‘cat’,’dog’,’mouse’]]} df = pd.DataFrame(raw_data, columns = [‘score’, ‘tags’]) /* view the dataset */ df score tags 0 1 apple,pear,guavaapple,pear,guava 1 2 truck,car,planetruck,car,plane 2 3 cat,dog,mousecat,dog,mouse …

Data Wrangling in Python – How to Do Descriptive Statistics For pandas Dataframe

Hits: 5 Descriptive Statistics For pandas Dataframe Import modules import pandas as pd Create dataframe data = {‘name’: [‘Jason’, ‘Molly’, ‘Tina’, ‘Jake’, ‘Amy’], ‘age’: [42, 52, 36, 24, 73], ‘preTestScore’: [4, 24, 31, 2, 3], ‘postTestScore’: [25, 94, 57, 62, 70]} df = pd.DataFrame(data, columns = [‘name’, ‘age’, ‘preTestScore’, ‘postTestScore’]) df name age preTestScore postTestScore …

Data Wrangling in Python – Creating Lists From Dictionary Keys And Values

Hits: 7 Creating Lists From Dictionary Keys And Values Create a dictionary dict = {‘county’: [‘Cochice’, ‘Pima’, ‘Santa Cruz’, ‘Maricopa’, ‘Yuma’], ‘year’: [2012, 2012, 2013, 2014, 2014], ‘fireReports’: [4, 24, 31, 2, 3]} Create a list from the dictionary keys /* Create a list of keys */ list(dict.keys()) [‘fireReports’, ‘year’, ‘county’] Create a list from …

Data Wrangling in Python – How to Create a Column Based on a Conditional in pandas

Hits: 1 Create a Column Based on a Conditional in pandas Preliminaries /* Import required modules */ import pandas as pd import numpy as np Make a dataframe data = {‘name’: [‘Jason’, ‘Molly’, ‘Tina’, ‘Jake’, ‘Amy’], ‘age’: [42, 52, 36, 24, 73], ‘preTestScore’: [4, 24, 31, 2, 3], ‘postTestScore’: [25, 94, 57, 62, 70]} df …