Python Data Analysis- Analytics vidhya

© All Rights Reserved

146 views

Python Data Analysis- Analytics vidhya

© All Rights Reserved

- Deep Learning Applications Using Python
- Pandas Cheat Sheet
- Python Matplotlib Cheat Sheet
- Pandas Python for Data Science
- Machine Learning Algorithms Applications
- Applied Deep Learning.pdf
- Scikit_Learn_Cheat_Sheet_Python.pdf
- Python Seaborn Cheat Sheet
- Data Analysis From Scratch With - Peters Morgan
- Skansi. S - Introduction to Deep Learning - 2018
- NumPy, SciPy, Pandas, Quandl Cheat Sheet
- Python Reference Card
- Artificial Intelligence With Python Tutorial
- Python 3 Cheat Sheet
- Beginners Python Cheat Sheet Pcc All
- scipy_and_numpy.pdf
- Pandas Cookbook [eBook]
- Python 3.2 Reference Card
- Website Scraping With Python
- Matplotlib Cheat Sheet

You are on page 1of 1

in Python USING

NumPy

Pandas

Matplotlib

data operations and

manipulations. It is

extensively used for data

munging and preparation.

Python. This library contains

basic linear algebra functions

Fourier transforms,advanced

random number capabilities.

library offers matplotlib

with a complete 2D support

along with limited 3D graphic

support.

CHEATSHEET

Contents

Data Exploration

2. How to convert a variable to different data type?

3. How to transpose a table?

4. How to sort Data?

5. How to create plots

(Histogram, Scatter, Box Plot)?

6. How to generate frequency tables?

7. How to do sampling of Data set?

8. How to remove duplicate values of a variable?

9. How to group variables to calculate count,

average, sum?

10. How to recognize and treat missing values

and outliers?

11. How to merge / join data set effectively?

Here are some common

functions used to read data

CODE

import pandas as pd

#Import Library Pandas

df = pd.read_csv("E:/train.csv") #I am working in Windows environment

#Reading the dataset in a dataframe using Pandas

print df.head(3) #Print first three observations

Output

CODE

df=pd.read_excel("E:/EMP.xlsx", "Data") # Load Data sheet of excel file EMP

CODE

# Load Data from text file having tab \t delimeter print df

df=pd.read_csv(E:/Test.txt,sep=\t)

- Convert numeric variables to string variables

and vice versa

srting_outcome = str(numeric_input) #Converts numeric_input to string_outcome

integer_outcome = int(string_input) #Converts string_input to integer_outcome

float_outcome = float(string_input) #Converts string_input to integer_outcome

from datetime import datetime

char_date = 'Apr 1 2015 1:20 PM' #creating example character date

date_obj = datetime.strptime(char_date, '% b % d % Y % I : % M % p')

print date_obj

- Data set used

Code

#Transposing dataframe by a variable

df=pd.read_excel("E:/transpose.xlsx", "Sheet1") # Load Data sheet of excel file EMP

print df

result= df.pivot(index= 'ID', columns='Product', values='Sales')

result

Output

CODE

#Sorting Dataframe

df=pd.read_excel("E:/transpose.xlsx", "Sheet1")

#Add by variable name(s) to sort

print df.sort(['Product','Sales'], ascending=[True, False])

Orginal Table

Sorted Table

Histogram

Code

OutPut

#Plot Histogram

import matplotlib.pyplot as plt

import pandas as pd

df=pd.read_excel("E:/First.xlsx", "Sheet1")

#Plots in matplotlib reside within a figure

object, use plt.figure to create new figure

fig=plt.figure()

#Create one or more subplots using

add_subplot, because you can't

create blank figure

ax = fig.add_subplot(1,1,1)

#Variable

ax.hist(df['Age'],bins = 5)

#Labels and Tit

plt.title('Age distribution')

plt.xlabel('Age')

plt.ylabel('#Employee')

plt.show()

Scatter plot

Code

OutPut

object, use plt.figure to create new figure

fig=plt.figure()

#Create one or more subplots using

add_subplot, because you can't

create blank figure

ax = fig.add_subplot(1,1,1)

#Variable

ax.scatter(df['Age'],df['Sales'])

#Labels and Tit

plt.title('Sales and Age distribution')

plt.xlabel('Age')

plt.ylabel('Sales')

plt.show()

Box-plot:

Code

OutPut

sns.boxplot(df['Age'])

sns.despine()

Code

OutPut

import pandas as pd

df=pd.read_excel("E:/First.xlsx", "Sheet1")

print df

test= df.groupby(['Gender','BMI'])

test.size()

100%

0%

Code

OutPut

import numpy as np

import pandas as pd

from random import sample

# create random index

rindex = np.array(sample(xrange(len(df)), 5))

# get 5 random rows from df

dfr = df.ix[rindex]

print dfr

Output

Code

#Remove Duplicate Values based on values

of variables "Gender" and "BMI"

rem_dup=df.drop_duplicates(['Gender', 'BMI'])

print rem_dup

Code

Output

test= df.groupby(['Gender'])

test.describe()

Output

Code

# Identify missing values of dataframe

df.isnull()

Code

#Example to impute missing values in Age by the mean

import numpy as np

#Using numpy mean function to calculate the mean value

meanAge = np.mean(df.Age)

#replacing missing values in the DataFrame

df.Age = df.Age.fillna(meanAge)

Code

# merges df1 and df2 on index

# By changing how = 'outer', you can do outer join.

# Similarly how = 'left' will do a left join

# You can also specify the columns to join instead of indexes, which are used by default.

- Deep Learning Applications Using PythonUploaded byBratva Ankit Mishra
- Pandas Cheat SheetUploaded byRoberto
- Python Matplotlib Cheat SheetUploaded bysreedhar
- Pandas Python for Data ScienceUploaded bychowdamhemalatha
- Machine Learning Algorithms ApplicationsUploaded byasadfx
- Applied Deep Learning.pdfUploaded byAmbrose Onueseke
- Scikit_Learn_Cheat_Sheet_Python.pdfUploaded byrakesharumalla
- Python Seaborn Cheat SheetUploaded byFrâncio Rodrigues
- Data Analysis From Scratch With - Peters MorganUploaded byWallisson Carvalho
- Skansi. S - Introduction to Deep Learning - 2018Uploaded byjeff ostroff
- NumPy, SciPy, Pandas, Quandl Cheat SheetUploaded byseanrwcrawford
- Python Reference CardUploaded bymarczucker
- Artificial Intelligence With Python TutorialUploaded byAnanth
- Python 3 Cheat SheetUploaded byLaurent Pointal
- Beginners Python Cheat Sheet Pcc AllUploaded byjohn smith
- scipy_and_numpy.pdfUploaded byAndrés Chavarría
- Pandas Cookbook [eBook]Uploaded byMarcos Filipe Godoy
- Python 3.2 Reference CardUploaded byLaurent Pointal
- Website Scraping With PythonUploaded byAnonymous Eg1W468aNv
- Matplotlib Cheat SheetUploaded byTuan Ton
- Python 3 Cheat SheetUploaded byFredrik Johansson
- Data Analysis and Visualization Using PythonUploaded byAndras Szilagyi
- Advanced Data Analytics Using PythonUploaded byJesse James Matos Soares
- Python Pandas TutorialUploaded byDavid Charles
- Python Machine LearningUploaded byArjun
- Numpy Cheat SheetUploaded byIan Flores
- Git Cheat SheetUploaded bykzelda
- Statistics For Machine LearningUploaded byDiamond Ravi
- PythonUploaded byJean Lucas
- Beyeler M. - Machine Learning for OpenCV - 2017Uploaded byTheThing81

- Physics Final (cheat sheet) with problemsUploaded byRSlipkov
- IGNOU_Forms for Use.pdfUploaded byAmbalika Smiti
- jnu_AdmissionAnnouncement2015Uploaded byBuntySingh
- Mps Ast 1st Year 10-11Uploaded byfeeamali1445
- Solid State Physics KittelUploaded byAmbalika Smiti
- 419788 Geometry CheatsheetUploaded byAmbalika Smiti
- Ignou Duplicate MarksheetUploaded byDileep Guleriya
- 2009 RBI.grade.B.phase 2.PapersUploaded byAmbalika Smiti
- Common Derivatives & IntegralsUploaded bystr8spades
- Math.cheat.sheet Too.cool.and.imp MustUploaded byAmbalika Smiti
- Delhi Metro - Daily Last Train DetailsUploaded byPankaj Vivek
- AgricultureUploaded byAmbalika Smiti
- List of Trigonometric IdentitiesUploaded byAmbalika Smiti
- Bachan Singh v State of Punjab 1980Uploaded byAmbalika Smiti
- Banking & FIsUploaded byAmbalika Smiti
- TaxationUploaded byAmbalika Smiti
- Structure of the Indian EconomyUploaded byAmbalika Smiti
- BudgetUploaded byAmbalika Smiti
- PlanningUploaded byAmbalika Smiti
- IndustryUploaded byAmbalika Smiti
- Formulae 0111Uploaded byAmbalika Smiti
- Fibre OpticsUploaded byAmbalika Smiti
- Trig Cheat SheetUploaded byHMaSN
- Calculus Cheat Sheet Limits Definitions Limit at Infinity :Uploaded byapi-11922418
- Algebra Cheat SheetUploaded byDino
- Abstract Algebra Cheat SheetUploaded bylpauling
- Trig Cheat SheetUploaded byDino
- Calculus Cheat SheetUploaded byDino

- API 751 .pdfUploaded byReda
- Reflections of Business Research MethodsUploaded byZoran Radusinovic
- ExamsUploaded bySuraj Singh
- A01460105.pdfUploaded byVanessa Van-Dyke
- Assig 1 - Analysis of Vision, Mission, Objective andUploaded byNour Ly
- p Apendice bUploaded byelena lopez alba
- Modeling and Simulation Lab 03.docxUploaded byAhmed Magdy
- Performance Management SystemUploaded byDakshata Gadiya
- Annual Report 2015Uploaded byAnonymous LceXBeu
- Human Relations MovementUploaded byAlain Dave Visitacion
- THC tests by retailers - Part 1Uploaded byWMBF News
- 114562573-Is-5816-Splitting-Tesile-Strength-of-Concrete-Method-of-Test-182112830.pdfUploaded byDeven Patle
- Lec17PattRec09.pdfUploaded byAmandeep Sharma
- katiemartinUploaded byapi-290536773
- protocol_4684-096-KUploaded bybnkjaya
- QuestionUploaded by6Ungu
- Overview of Severity SystemsUploaded byisleofthedeep08
- 2. GMP & Validation.pptUploaded bykomalindustries7352
- ASSIGNMENT 2-QUANTITATIVE.docxUploaded byShearer Alans
- Planning for a Very Long Term vs for a Very Short TermUploaded byYATIN JM
- Benign Prostatic Hyperplasia in Community-Dwelling Elderly in KoreaUploaded byTri Myly
- EMDR MigrainesUploaded byVirginia Mora
- Honesty in Multicultural CounselingUploaded byMirza Irawan
- fa04_lecture1Uploaded byDr. Ir. R. Didin Kusdian, MT.
- Aldi Case Analysis FINALUploaded byOsamaNaseemKhan
- Journal Review - Analytical Model for FRP-And-Steel-Confined Circular Concrete Columns in CompressionUploaded byOswaldo Russián
- Auditing Your Organization's StrategyUploaded byTriarchy Press
- Principle of business ch8Uploaded byrt
- Kendall Sad8e Ch04Uploaded byيو يو
- Brand EquityUploaded byRafa Casti