Start with Python and Pandas – Part 1

Hello Friends!! recently I started with Python again. I’ll share basic intro to python. I’m be using Jupyter notebook for the tutorial. This will require a basic understanding of programming knowledge to understand the flow. Syntax are bit similar to R so if you know it will be easy to catch.

Import Pandas

import pandas as pd

Check default Working directory

%pwd

Change working directory

%cd "C:\Users\kedia niket\Documents\Python"
# %cd and then the location you want add

Reading csv file

input = pd.read_csv('titanic.csv')

Check type of any input

type(input)
#will return pandas.core.frame.DataFrame so Dataframe is the type of the input

Get basic stats about the numerical columns

input.describe()

Result:

PassengerIdSurvivedPclassAgeSibSpParchFare
count891.0891.0891.0714.0891.0891.0891.0
mean446.00.42.329.70.50.432.2
std257.40.50.814.51.10.849.7
min1.00.01.00.40.00.00.0
25%223.50.02.020.10.00.07.9
50%446.00.03.028.00.00.014.5
75%668.51.03.038.01.00.031.0
max891.01.03.080.08.06.0512.3

Get data frame size

input.shape
# will return (# rows, # columns)

input.shape[0]
# will return # rows


input.shape[1]
# will return # columns

Get the top n rows and bottom n rows of the data

input.head()
# get top 5 rows


input.head(n)
# get top n rows


input.tail()
# get bottom 5 rows


input.tail(n)
# get bottom n rows

Get column names

input.columns
#will return the column header

Keep visiting Analytics Tuts for more tutorials.

Thanks for reading! Comment your suggestions and queries



One comment

Leave a Reply

Your email address will not be published. Required fields are marked *