0% found this document useful (0 votes)
138 views

Day-18 (Pandas in Python)

This document provides an overview of Pandas in Python. It discusses that Pandas is an open source library for data manipulation and analysis. Pandas has two main data structures: Series and DataFrames. Series are single-dimensional arrays, while DataFrames are 2D arrays with rows and columns for storing data. The document also demonstrates how to install Pandas, create Pandas Series and DataFrames from various data, and read data from CSV files into DataFrames.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
138 views

Day-18 (Pandas in Python)

This document provides an overview of Pandas in Python. It discusses that Pandas is an open source library for data manipulation and analysis. Pandas has two main data structures: Series and DataFrames. Series are single-dimensional arrays, while DataFrames are 2D arrays with rows and columns for storing data. The document also demonstrates how to install Pandas, create Pandas Series and DataFrames from various data, and read data from CSV files into DataFrames.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

10/24/2020 Day-18 [ Pandas in Python]

In [ ]: #Agenda of Today :
1. Pandas in python Programming.
#What are pandas?
--- Its on Open Source Python Library Providing High- Performance on
(i) Data Manipulation
(ii) Data Analysis
(iii) Data Cleaning.
--- Pandas having two Powerful data Structures
(a) Data Series
(b) Data Frames
--- Mostly we work data sets in the form ..csv files (Comma separated values )
--- Pandas - the name sis derived from the word panel data - an Econometrics from Multidemensional Data.

#Author : Wes McKinney


#First Release : july,2018
#Written in : Python Programming
#Pandas Applications.
---Pandas is mainly worked with
1. Tabular Data
2. Ordered and Unordered times series Data
3. Arbitrary matrix data with row & coloumns labels
4. Unlalled Data
5. Observational or Statistical Data Sets.

In [ ]: #How to install pandas?


pip install pandas - #IDLE users
conda install pandas - #Anaconda users

In [1]: #How to use pandas?


import pandas as pd

localhost:8888/nbconvert/html/Desktop/Python_Online_Programmingg/Day-18 %5B Pandas in Python%5D.ipynb?download=false 1/23


10/24/2020 Day-18 [ Pandas in Python]

In [9]: #Pandas Data Structures: (Data Series and Data Frames)


#Data Series: Its a Single-Dimensional Data Structure and its having any data type of elements.

#syntax: pd.Series(data,index=INDEX)

import pandas as pd
import numpy as np
s1 = pd.Series([1,2,3],index = ["A","B","C"])
s2 = pd.Series(["python","java","C",123],index = ["1","2","3","4"])
s3 = pd.Series(["Yes","NO",np.nan])
print(s1)
print(s2)
print(s3)

A 1
B 2
C 3
dtype: int64
1 python
2 java
3 C
4 123
dtype: object
0 Yes
1 NO
2 NaN
dtype: object

localhost:8888/nbconvert/html/Desktop/Python_Online_Programmingg/Day-18 %5B Pandas in Python%5D.ipynb?download=false 2/23


10/24/2020 Day-18 [ Pandas in Python]

In [16]: #Data Frames:


#Its 2-D array and Data is stored in the form of rows and columns.
#Here, row can store the information (Data ) and Columns can store the names of information.
#syntax: pd.DataFrame(data,index=INDEX)

import pandas as pd
import numpy as np
data = [[1,2],[3,4]]
df= pd.DataFrame(data)
print("Numpy to Pandas :")
print(df)
#pandas to Numpy
df_2np= np.array(df)
print("Pandas to Numpy array:")
print(df_2np)

Numpy to Pandas :
0 1
0 1 2
1 3 4
Pandas to Numpy array:
[[1 2]
[3 4]]

localhost:8888/nbconvert/html/Desktop/Python_Online_Programmingg/Day-18 %5B Pandas in Python%5D.ipynb?download=false 3/23


10/24/2020 Day-18 [ Pandas in Python]

In [22]: #eX:
import pandas as pd
df1=pd.DataFrame([20,"abc","xyz","python","APSSDC"],index=["A","B","C","D","E"])
dic = {"Name":["Karthik","Kalyan","Surya"],"Profession":["Tester","HR","Devloper"]}
df2= pd.DataFrame(dic,index=["A","B","C"])
print(df1)
df2

0
A 20
B abc
C xyz
D python
E APSSDC

Out[22]:
Name Profession

A Karthik Tester

B Kalyan HR

C Surya Devloper

localhost:8888/nbconvert/html/Desktop/Python_Online_Programmingg/Day-18 %5B Pandas in Python%5D.ipynb?download=false 4/23


10/24/2020 Day-18 [ Pandas in Python]

In [30]: #how to create random pandas Data Frames:(inspecting Data in DataFrames)


import pandas as pd
import numpy as np
n1=np.random.randn(6,4)
df=pd.DataFrame(n1,columns=list('ABCD'))
print(df.head(2))
print(df.tail(3))
print(df.describe())

A B C D
0 0.896784 0.078942 -1.086899 -0.049722
1 1.839803 -0.163002 1.398003 0.336483
A B C D
3 -0.863633 1.122176 -0.663525 1.354798
4 0.110107 -1.351800 -1.381173 -1.170147
5 -0.047481 -1.669570 0.389685 -0.358035
A B C D
count 6.000000 6.000000 6.000000 6.000000
mean 0.364832 -0.290769 -0.149120 0.248274
std 0.918143 1.044661 1.068071 0.997283
min -0.863633 -1.669570 -1.381173 -1.170147
25% -0.008084 -1.054601 -0.981056 -0.280956
50% 0.181761 -0.042030 -0.136920 0.143381
75% 0.735941 0.198717 0.434316 1.100219
max 1.839803 1.122176 1.398003 1.376266

localhost:8888/nbconvert/html/Desktop/Python_Online_Programmingg/Day-18 %5B Pandas in Python%5D.ipynb?download=false 5/23


10/24/2020 Day-18 [ Pandas in Python]

In [46]: #how to read csv/data set file using pandas:


import pandas as pd
df=pd.read_csv("Empdata.csv")
df.head(5)
df.tail(5)
df.describe()
df

localhost:8888/nbconvert/html/Desktop/Python_Online_Programmingg/Day-18 %5B Pandas in Python%5D.ipynb?download=false 6/23


10/24/2020 Day-18 [ Pandas in Python]

Out[46]:
Mother's
Emp Name First Middle Father's Mother's
Last Name Gender E Mail Maiden ...
ID Prefix Name Initial Name Name
Name

Rosario
0 850297 Ms. Shawna W Buck F [email protected] Keisha Buck Hendricks ...
Buck

Derrick Phoebe
1 304721 Mr. Nathaniel Z Burke M [email protected] Pugh ...
Burke Burke

2 412317 Drs. Elisabeth W Foster F [email protected] Irwin Foster Janie Foster Delaney ...

Jeffrey Shelby
3 621375 Mrs. Briana C Lancaster F [email protected] Weiss ...
Lancaster Lancaster

Booker Katelyn
4 787549 Hon. Estella L Potter F [email protected] Pate ...
Potter Potter

Ignacio Beulah
5 520092 Mr. Lamont L Woods M [email protected] Trujillo ...
Woods Woods

6 795934 Ms. Melinda L Lopez F [email protected] Leroy Lopez Edna Lopez Carter ...

7 159108 Mrs. Shanna U Silva F [email protected] Eliseo Silva Minnie Silva Callahan ...

Hans Renee
8 330816 Ms. Jasmine J Freeman F [email protected] Mcbride ...
Freeman Freeman

Luke Judy
9 532002 Ms. Madge V Sargent F [email protected] Herrera ...
Sargent Sargent

Deanne
10 612850 Ms. Bethany Z Cline F [email protected] Eddie Cline Gordon ...
Cline

Grover Erika
11 483751 Prof. Reid F Randolph M [email protected] Melendez ...
Randolph Randolph

localhost:8888/nbconvert/html/Desktop/Python_Online_Programmingg/Day-18 %5B Pandas in Python%5D.ipynb?download=false 7/23


10/24/2020 Day-18 [ Pandas in Python]

Mother's
Emp Name First Middle Father's Mother's
Last Name Gender E Mail Maiden ...
ID Prefix Name Initial Name Name
Name

Frances
12 252938 Hon. Antoine H Wiley M [email protected] Naomi Wiley Kirby ...
Wiley

Prince Regina
13 966375 Dr. Mathew O Hodge M [email protected] Henderson ...
Hodge Hodge

Lowell Shauna
14 707520 Mr. Bernardo L Austin M [email protected] Humphrey ...
Austin Austin

Terence Belinda
15 673049 Dr. Cole E Jensen M [email protected] Brown ...
Jensen Jensen

Johnathan Brianna
16 265124 Ms. Tonia J Burns F [email protected] Lester ...
Burns Burns

Gail Beulah
17 300693 Mr. Tod N Holcomb M [email protected] Keller ...
Holcomb Holcomb

Alfred Lori
18 369712 Mrs. Yesenia B Guerrero F [email protected] Joyner ...
Guerrero Guerrero

Robby Christi
19 913253 Mr. Carey B Ferrell M [email protected] Bradshaw ...
Ferrell Ferrell

Kurt Virgie
20 308617 Mrs. Aileen D Blanchard F [email protected] Christian ...
Blanchard Blanchard

Fletcher Hazel
21 766783 Mrs. Marta N Cervantes F [email protected] Singleton ...
Cervantes Cervantes

Reggie Rosemarie
22 959506 Mr. Arthur Q Holloway M [email protected] Pope ...
Holloway Holloway

Davis
23 513011 Ms. Tara Y Forbes F [email protected] Elvia Forbes Gonzalez ...
Forbes

localhost:8888/nbconvert/html/Desktop/Python_Online_Programmingg/Day-18 %5B Pandas in Python%5D.ipynb?download=false 8/23


10/24/2020 Day-18 [ Pandas in Python]

Mother's
Emp Name First Middle Father's Mother's
Last Name Gender E Mail Maiden ...
ID Prefix Name Initial Name Name
Name

Leonor
24 290808 Mr. Josef S Griffin M [email protected] Dee Griffin Glass ...
Griffin

Jeanne
25 253588 Ms. Keri J Slater F [email protected] Tyler Slater Bowman ...
Slater

Marianne
26 865628 Mr. Desmond R Wynn M [email protected] Louis Wynn Dennis ...
Wynn

Fletcher Nicole
27 583924 Mrs. Adrienne H Puckett F [email protected] Barron ...
Puckett Puckett

Jackson Ava
28 932453 Mrs. Beatriz I Knowles F [email protected] Horton ...
Knowles Knowles

Sheila
29 432168 Hon. Jermaine S Sykes M [email protected] Garth Sykes Dorsey ...
Sykes

... ... ... ... ... ... ... ... ... ... ... ...

Alphonse Annette
970 329548 Mr. Phil B Montgomery M [email protected] Hubbard ...
Montgomery Montgomery

Gus Candice
971 955183 Mr. Jonas L Underwood M [email protected] Mcclain ...
Underwood Underwood

Kennith Jeannette
972 862947 Mrs. Benita H Mcgee F [email protected] Potter ...
Mcgee Mcgee

Houston Louise
973 174542 Ms. Rochelle R Guerrero F [email protected] Carson ...
Guerrero Guerrero

Marion
974 857324 Drs. Terra Z Webb F [email protected] Denis Webb Boyer ...
Webb

Diego Stacie
975 678498 Mr. Buford Y Zimmerman M [email protected] Edwards ...
Zimmerman Zimmerman

localhost:8888/nbconvert/html/Desktop/Python_Online_Programmingg/Day-18 %5B Pandas in Python%5D.ipynb?download=false 9/23


10/24/2020 Day-18 [ Pandas in Python]

Mother's
Emp Name First Middle Father's Mother's
Last Name Gender E Mail Maiden ...
ID Prefix Name Initial Name Name
Name

Myron Rochelle
976 661971 Mr. Emanuel X Nichols M [email protected] Pace ...
Nichols Nichols

Rusty Lorena
977 537235 Ms. Cheryl M French F [email protected] Padilla ...
French French

Refugio Marissa
978 712170 Mr. Theodore T Dale M [email protected] Moran ...
Dale Dale

Jarrett Alexandria
979 285184 Mrs. Ginger H Palmer F [email protected] Cooper ...
Palmer Palmer

Tabitha
980 994907 Hon. Lilian L Stein F [email protected] Sung Stein Valenzuela ...
Stein

Marquita
981 523887 Mr. Gilbert L Luna M [email protected] Scotty Luna Pena ...
Luna

Hunter Maude
982 684722 Mr. Waldo B Wright M [email protected] Woodard ...
Wright Wright

Angel Twila
983 792224 Mr. Tommie Y Cunningham M [email protected] Booker ...
Cunningham Cunningham

Margery
984 199699 Prof. George W Potts M [email protected] Merrill Potts Poole ...
Potts

Pasquale Tanisha
985 953997 Mr. Graham F Hutchinson M [email protected] Cook ...
Hutchinson Hutchinson

Dolores
986 149818 Mrs. Ophelia Z Pena F [email protected] Rick Pena Romero ...
Pena

Isabella
987 352882 Dr. Lon P Harper M [email protected] Abel Harper Kennedy ...
Harper

localhost:8888/nbconvert/html/Desktop/Python_Online_Programmingg/Day-18 %5B Pandas in Python%5D.ipynb?download=false 10/23


10/24/2020 Day-18 [ Pandas in Python]

Mother's
Emp Name First Middle Father's Mother's
Last Name Gender E Mail Maiden ...
ID Prefix Name Initial Name Name
Name

988 760995 Mr. Irvin V Witt M [email protected] Carlo Witt Ericka Witt Terrell ...

Nichole
989 873626 Mrs. Sheri A Spears F [email protected] Jody Spears Blanchard ...
Spears

990 247051 Ms. Alberta A Page F [email protected] Efrain Page Tania Page Santos ...

Morton
991 715045 Drs. Kerri Q Santos F [email protected] Ada Santos Christian ...
Santos

Juanita
992 601808 Mr. Olin N Case M [email protected] Daryl Case Marquez ...
Case

Reed Darlene
993 569286 Mr. Stefan L Jacobs M [email protected] Vaughan ...
Jacobs Jacobs

Sheldon Rachael
994 172440 Dr. Cody H Allison M [email protected] Harrington ...
Allison Allison

Edwardo Pauline
995 568435 Ms. Bonnie K Baker F [email protected] Robinson ...
Baker Baker

Javier Nicole
996 597409 Mr. Luke S Turner M [email protected] Sykes ...
Turner Turner

Haley
997 359608 Hon. Eva S Holman F [email protected] Coy Holman Boyle ...
Holman

Dion Stephanie
998 803426 Mrs. Maritza H Christian F [email protected] Mooney ...
Christian Christian

Jarrod Latisha
999 669618 Drs. Phyllis H Dudley F [email protected] Wilcox ...
Dudley Dudley

1000 rows × 37 columns


localhost:8888/nbconvert/html/Desktop/Python_Online_Programmingg/Day-18 %5B Pandas in Python%5D.ipynb?download=false 11/23
10/24/2020 Day-18 [ Pandas in Python]

localhost:8888/nbconvert/html/Desktop/Python_Online_Programmingg/Day-18 %5B Pandas in Python%5D.ipynb?download=false 12/23


10/24/2020 Day-18 [ Pandas in Python]

In [50]: #Slicing the data in Dataframe


df[0:3]
df.loc[:,["Emp ID","Salary","First Name"]]
df.drop(columns=["Emp ID","Name Prefix","Gender"])

localhost:8888/nbconvert/html/Desktop/Python_Online_Programmingg/Day-18 %5B Pandas in Python%5D.ipynb?download=false 13/23


10/24/2020 Day-18 [ Pandas in Python]

Out[50]:
Mother's Age
First Middle Father's Mother's Date of Time of
Last Name E Mail Maiden in
Name Initial Name Name Birth Birth
Name Yrs.

Rosario 06:34:47
0 Shawna W Buck [email protected] Keisha Buck Hendricks 12/12/1971 45.66
Buck AM

Derrick Phoebe 02:02:38


1 Nathaniel Z Burke [email protected] Pugh 10/31/1993 23.76
Burke Burke AM

03:48:27
2 Elisabeth W Foster [email protected] Irwin Foster Janie Foster Delaney 11/26/1994 22.68
PM

Jeffrey Shelby 09:44:16


3 Briana C Lancaster [email protected] Weiss 11/24/1975 41.70
Lancaster Lancaster PM

Booker Katelyn 09:30:28


4 Estella L Potter [email protected] Pate 3/13/1995 22.39
Potter Potter PM

Ignacio Beulah 07:19:41


5 Lamont L Woods [email protected] Trujillo 10/13/1991 25.81
Woods Woods AM

01:31:34
6 Melinda L Lopez [email protected] Leroy Lopez Edna Lopez Carter 9/15/1984 32.89
PM

12:42:34
7 Shanna U Silva [email protected] Eliseo Silva Minnie Silva Callahan 6/19/1958 59.15
PM

Hans Renee 05:28:26


8 Jasmine J Freeman [email protected] Mcbride 8/31/1961 55.95
Freeman Freeman AM

Luke Judy 05:09:07


9 Madge V Sargent [email protected] Herrera 10/2/1981 35.84
Sargent Sargent PM

Deanne 05:22:21
10 Bethany Z Cline [email protected] Eddie Cline Gordon 10/1/1986 30.84
Cline AM

Grover Erika 11:39:31


11 Reid F Randolph [email protected] Melendez 1/20/1989 28.54
Randolph Randolph PM

localhost:8888/nbconvert/html/Desktop/Python_Online_Programmingg/Day-18 %5B Pandas in Python%5D.ipynb?download=false 14/23


10/24/2020 Day-18 [ Pandas in Python]

Mother's Age
First Middle Father's Mother's Date of Time of
Last Name E Mail Maiden in
Name Initial Name Name Birth Birth
Name Yrs.

Frances 06:29:11
12 Antoine H Wiley [email protected] Naomi Wiley Kirby 2/22/1996 21.44
Wiley PM

Prince Regina 03:24:44


13 Mathew O Hodge [email protected] Henderson 7/5/1995 22.08
Hodge Hodge PM

Lowell Shauna 11:18:06


14 Bernardo L Austin [email protected] Humphrey 2/2/1975 42.51
Austin Austin PM

Terence Belinda 07:36:01


15 Cole E Jensen [email protected] Brown 2/10/1990 27.48
Jensen Jensen PM

Johnathan Brianna 10:44:02


16 Tonia J Burns [email protected] Lester 4/19/1985 32.30
Burns Burns PM

Gail Beulah 05:10:47


17 Tod N Holcomb [email protected] Keller 6/21/1987 30.12
Holcomb Holcomb AM

Alfred Lori 04:24:45


18 Yesenia B Guerrero [email protected] Joyner 3/29/1968 49.36
Guerrero Guerrero PM

Robby Christi 04:16:53


19 Carey B Ferrell [email protected] Bradshaw 5/22/1972 45.21
Ferrell Ferrell PM

Kurt Virgie 11:18:17


20 Aileen D Blanchard [email protected] Christian 12/5/1986 30.67
Blanchard Blanchard AM

Fletcher Hazel 08:46:37


21 Marta N Cervantes [email protected] Singleton 2/17/1971 46.47
Cervantes Cervantes AM

Reggie Rosemarie 11:57:43


22 Arthur Q Holloway [email protected] Pope 9/21/1970 46.88
Holloway Holloway PM

Davis 07:47:36
23 Tara Y Forbes [email protected] Elvia Forbes Gonzalez 6/26/1976 41.12
Forbes PM

localhost:8888/nbconvert/html/Desktop/Python_Online_Programmingg/Day-18 %5B Pandas in Python%5D.ipynb?download=false 15/23


10/24/2020 Day-18 [ Pandas in Python]

Mother's Age
First Middle Father's Mother's Date of Time of
Last Name E Mail Maiden in
Name Initial Name Name Birth Birth
Name Yrs.

Leonor 04:28:48
24 Josef S Griffin [email protected] Dee Griffin Glass 8/14/1976 40.98
Griffin AM

Jeanne 11:14:40
25 Keri J Slater [email protected] Tyler Slater Bowman 8/3/1960 57.02
Slater AM

Marianne 04:39:00
26 Desmond R Wynn [email protected] Louis Wynn Dennis 7/9/1992 25.07
Wynn AM

Fletcher Nicole 11:45:23


27 Adrienne H Puckett [email protected] Barron 5/22/1975 42.21
Puckett Puckett AM

Jackson Ava 12:06:41


28 Beatriz I Knowles [email protected] Horton 2/25/1984 33.44
Knowles Knowles PM

Sheila 04:48:36
29 Jermaine S Sykes [email protected] Garth Sykes Dorsey 1/18/1990 27.54
Sykes AM

... ... ... ... ... ... ... ... ... ... ...

Alphonse Annette 02:09:47


970 Phil B Montgomery [email protected] Hubbard 11/13/1991 25.72
Montgomery Montgomery AM

Gus Candice 09:21:38


971 Jonas L Underwood [email protected] Mcclain 7/13/1995 22.06
Underwood Underwood AM

Kennith Jeannette 06:29:12


972 Benita H Mcgee [email protected] Potter 12/30/1970 46.61
Mcgee Mcgee PM

Houston Louise 03:21:12


973 Rochelle R Guerrero [email protected] Carson 9/10/1992 24.90
Guerrero Guerrero PM

Marion 02:13:49
974 Terra Z Webb [email protected] Denis Webb Boyer 7/1/1973 44.10
Webb PM

Diego Stacie 07:15:42


975 Buford Y Zimmerman [email protected] Edwards 9/4/1994 22.91
Zimmerman Zimmerman AM

localhost:8888/nbconvert/html/Desktop/Python_Online_Programmingg/Day-18 %5B Pandas in Python%5D.ipynb?download=false 16/23


10/24/2020 Day-18 [ Pandas in Python]

Mother's Age
First Middle Father's Mother's Date of Time of
Last Name E Mail Maiden in
Name Initial Name Name Birth Birth
Name Yrs.

Myron Rochelle 10:39:26


976 Emanuel X Nichols [email protected] Pace 6/5/1962 55.18
Nichols Nichols PM

Rusty Lorena 11:56:43


977 Cheryl M French [email protected] Padilla 8/20/1985 31.96
French French AM

Refugio Marissa 01:23:58


978 Theodore T Dale [email protected] Moran 12/17/1994 22.63
Dale Dale AM

Jarrett Alexandria 02:52:11


979 Ginger H Palmer [email protected] Cooper 5/23/1978 39.21
Palmer Palmer PM

Tabitha 06:46:15
980 Lilian L Stein [email protected] Sung Stein Valenzuela 6/23/1996 21.11
Stein AM

Marquita 09:59:08
981 Gilbert L Luna [email protected] Scotty Luna Pena 10/1/1968 48.85
Luna AM

Hunter Maude 07:05:09


982 Waldo B Wright [email protected] Woodard 1/26/1973 44.53
Wright Wright PM

Angel Twila 12:40:31


983 Tommie Y Cunningham [email protected] Booker 7/12/1977 40.07
Cunningham Cunningham AM

Margery 08:22:37
984 George W Potts [email protected] Merrill Potts Poole 1/13/1961 56.58
Potts PM

Pasquale Tanisha 08:31:57


985 Graham F Hutchinson [email protected] Cook 5/18/1985 32.22
Hutchinson Hutchinson AM

Dolores 11:28:05
986 Ophelia Z Pena [email protected] Rick Pena Romero 1/11/1986 31.56
Pena PM

Isabella 04:51:05
987 Lon P Harper [email protected] Abel Harper Kennedy 4/24/1994 23.28
Harper PM

localhost:8888/nbconvert/html/Desktop/Python_Online_Programmingg/Day-18 %5B Pandas in Python%5D.ipynb?download=false 17/23


10/24/2020 Day-18 [ Pandas in Python]

Mother's Age
First Middle Father's Mother's Date of Time of
Last Name E Mail Maiden in
Name Initial Name Name Birth Birth
Name Yrs.

12:55:00
988 Irvin V Witt [email protected] Carlo Witt Ericka Witt Terrell 1/25/1993 24.52
PM

Nichole 12:00:06
989 Sheri A Spears [email protected] Jody Spears Blanchard 1/7/1982 35.58
Spears AM

10:55:47
990 Alberta A Page [email protected] Efrain Page Tania Page Santos 2/5/1981 36.50
AM

Morton 03:30:34
991 Kerri Q Santos [email protected] Ada Santos Christian 11/10/1982 34.74
Santos AM

Juanita 12:17:21
992 Olin N Case [email protected] Daryl Case Marquez 6/6/1991 26.16
Case PM

Reed Darlene 09:18:27


993 Stefan L Jacobs [email protected] Vaughan 9/26/1983 33.86
Jacobs Jacobs AM

Sheldon Rachael 09:56:00


994 Cody H Allison [email protected] Harrington 12/23/1988 28.61
Allison Allison AM

Edwardo Pauline 12:06:26


995 Bonnie K Baker [email protected] Robinson 8/3/1985 32.01
Baker Baker PM

Javier Nicole 02:49:18


996 Luke S Turner [email protected] Sykes 2/12/1987 30.48
Turner Turner PM

Haley 12:46:23
997 Eva S Holman [email protected] Coy Holman Boyle 9/26/1957 59.88
Holman PM

Dion Stephanie 05:03:13


998 Maritza H Christian [email protected] Mooney 5/19/1987 30.21
Christian Christian AM

Jarrod Latisha 06:16:49


999 Phyllis H Dudley [email protected] Wilcox 11/2/1957 59.78
Dudley Dudley PM

1000 rows × 34 columns


localhost:8888/nbconvert/html/Desktop/Python_Online_Programmingg/Day-18 %5B Pandas in Python%5D.ipynb?download=false 18/23
10/24/2020 Day-18 [ Pandas in Python]

localhost:8888/nbconvert/html/Desktop/Python_Online_Programmingg/Day-18 %5B Pandas in Python%5D.ipynb?download=false 19/23


10/24/2020 Day-18 [ Pandas in Python]

In [57]: #Contatenation of DataFrames:


import pandas as pd
dic1 = {"Name":["Karthik","Kalyan","Surya"],"Profession":["Tester","HR","Devloper"]}
dic2 = {"Name":["Karthik","Kalyan","Surya"],"Age":[23,24,25]}
df1 = pd.DataFrame(dic1,index =[1,2,3])
df2 = pd.DataFrame(dic2,index =[4,5,6])
print(df1)
print(df2)
df_concat = pd.concat([df1,df2])
df_concat

Name Profession
1 Karthik Tester
2 Kalyan HR
3 Surya Devloper
Name Age
4 Karthik 23
5 Kalyan 24
6 Surya 25

C:\ProgramData\Anaconda3\lib\site-packages\ipykernel_launcher.py:9: FutureWarning: Sorting because non-concat


enation axis is not aligned. A future version
of pandas will change to not sort by default.

To accept the future behavior, pass 'sort=False'.

To retain the current behavior and silence the warning, pass 'sort=True'.

if __name__ == '__main__':

Out[57]:
Age Name Profession

1 NaN Karthik Tester

2 NaN Kalyan HR

3 NaN Surya Devloper

4 23.0 Karthik NaN

5 24.0 Kalyan NaN

6 25.0 Surya NaN

localhost:8888/nbconvert/html/Desktop/Python_Online_Programmingg/Day-18 %5B Pandas in Python%5D.ipynb?download=false 20/23


10/24/2020 Day-18 [ Pandas in Python]

In [60]: #drop_the Duplicates columns names


print(df_concat)
df_concat.drop_duplicates('Name')

Age Name Profession


1 NaN Karthik Tester
2 NaN Kalyan HR
3 NaN Surya Devloper
4 23.0 Karthik NaN
5 24.0 Kalyan NaN
6 25.0 Surya NaN

Out[60]:
Age Name Profession

1 NaN Karthik Tester

2 NaN Kalyan HR

3 NaN Surya Devloper

In [61]: #sort the values:


df_concat.sort_values('Age')

Out[61]:
Age Name Profession

4 23.0 Karthik NaN

5 24.0 Kalyan NaN

6 25.0 Surya NaN

1 NaN Karthik Tester

2 NaN Kalyan HR

3 NaN Surya Devloper

localhost:8888/nbconvert/html/Desktop/Python_Online_Programmingg/Day-18 %5B Pandas in Python%5D.ipynb?download=false 21/23


10/24/2020 Day-18 [ Pandas in Python]

In [62]: #rename : change of columns names


df_concat.rename(columns={"Name":"Profile Name","Age":"User Age"})

Out[62]:
User Age Profile Name Profession

1 NaN Karthik Tester

2 NaN Kalyan HR

3 NaN Surya Devloper

4 23.0 Karthik NaN

5 24.0 Kalyan NaN

6 25.0 Surya NaN

localhost:8888/nbconvert/html/Desktop/Python_Online_Programmingg/Day-18 %5B Pandas in Python%5D.ipynb?download=false 22/23


10/24/2020 Day-18 [ Pandas in Python]

In [70]: #merging of data frames


import pandas as pd
pd.merge(df1,df2)
print(pd.concat([df1,df2]))
print(pd.concat([df1,df2]))

Age Name Profession


1 NaN Karthik Tester
2 NaN Kalyan HR
3 NaN Surya Devloper
4 23.0 Karthik NaN
5 24.0 Kalyan NaN
6 25.0 Surya NaN
Age Name Profession
1 NaN Karthik Tester
2 NaN Kalyan HR
3 NaN Surya Devloper
4 23.0 Karthik NaN
5 24.0 Kalyan NaN
6 25.0 Surya NaN

C:\ProgramData\Anaconda3\lib\site-packages\ipykernel_launcher.py:4: FutureWarning: Sorting because non-concat


enation axis is not aligned. A future version
of pandas will change to not sort by default.

To accept the future behavior, pass 'sort=False'.

To retain the current behavior and silence the warning, pass 'sort=True'.

after removing the cwd from sys.path.


C:\ProgramData\Anaconda3\lib\site-packages\ipykernel_launcher.py:5: FutureWarning: Sorting because non-concat
enation axis is not aligned. A future version
of pandas will change to not sort by default.

To accept the future behavior, pass 'sort=False'.

To retain the current behavior and silence the warning, pass 'sort=True'.

"""

In [ ]:

localhost:8888/nbconvert/html/Desktop/Python_Online_Programmingg/Day-18 %5B Pandas in Python%5D.ipynb?download=false 23/23

You might also like