Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
100%
(2)
100% found this document useful (2 votes)
279 views
11 pages
Pandas Assignment
Uploaded by
Akshay Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save Pandas Assignment For Later
Share
100%
100% found this document useful, undefined
0%
, undefined
Print
Embed
Report
100%
(2)
100% found this document useful (2 votes)
279 views
11 pages
Pandas Assignment
Uploaded by
Akshay Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save Pandas Assignment For Later
Share
100%
100% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save Pandas Assignment For Later
You are on page 1
/ 11
Search
Fullscreen
119178, 947 Pat 10,,Pandas Assignment Day 10pynd - Colaboratory Pandas Assignment Import pandas and numpy with ther aliases Create a variable 14 Seres({ 100,200,300, 400)) 2 = paasertes( 200, 308, 468)) Print, and datatype Using indexing access the element 300 from the series 2 print(atay) What ate the values of index fr series a? print(index) Printivalues) Rangerndex(starteo, stops, stapes) [ee 200 390 423) Change the index to fb] 2 = pe.sentes(( 200, 208, 300, 400), index = ("2") “2 [Access the value inthe series with index print¢at'a"]) Intps:ifeolab research google. com/érva/taFLOIVZret76aT sD 7gACRWCeNW_wuottontMode=tu an119178, 947 Pat 410,,Pandas Assignment Day 10pyno Sort the values wrt tothe index and print t assort_index(oxis = 0) ‘ype ante Create a new Pandas Series b having index as‘, and and value 800,450,100 and prit it b= pe.sentes(( 680, 459, 100), index = ("e", "€, “ely ‘Append series at the end ofa series 2 = buappendcay Sort the values in descending order of a and print he index ofthe sorted series 2 + ausort_indextonis = @) Pandas DataFrame ntps:ifeolab rosearch google. com/érvel fgFLOIVZref7aTxDTeACRWCeNW_wuottorintMod: Colaboratory at119178, 947 Pat 10,,Pandas Assignment Day 10pynd - Colaboratory Part 1 Create a pandas dataframe df from the series's' that we used in the last section print the dataframe oF = pa.vatatrane({ 209, 200, 360, 499, #90, 458, 1681) eFsne390) 100 +200 3400 Whats the shape ofthe datafarme (also, what does it imply?) oy Hey! remember shape (7,1) mplles dataframe has 7 rows and 1 column, Whats the index ofthe dataframe, ist same as the series A yep As same a5 the serses printtindex Rangelndex(starte®, stope7, stapes) print the head and tall ofthe dataframe ‘Addiional- (what does head and taliepresent?) © 100 + 200 3400 4 a0 Intps:ifeolab roscarch google. com/drva/taFLOIVZret76aTxD7eACRWCeNW_wuottorntMode=tue119123, 947 PM 10,,Pandas Assignment Day 10pynd - Colaboratory print(af.nead(2)) print(af.tati(2)) Rename the column ofthe dataframe as points f.renane(colunnss{°2": points"), inplacesTrue) 100 3400 4 800 Create another Seles ute, which contains random names of tuts from [orangemangsapple randomly selected from [orangemangoapple] fruits = (orange, "ango",‘sppte") fruits = pe.series(("orange’,"nango'y'spple']) (Change the index of futs tothe index of dataframe d fruits = pe.oatafrane({#euses* = (orange, “nango',appte"1)) ‘Add this ute series asa new column to the dataftame df with its column name as fru print the head ofthe dataframe to verity Intps:feolab roscarch google. com/érvaltgFLOIVZret76aTuD7eACRWCeNW_wuottorntMode=tue he series should contaln 7 elements, am1191723, 947 Pat 10,,Pandas Assignment Day 10pynd - Colaboratory efsneaso) Pandas Concatenation Create a datatrame di where the cols are ‘ty :['Chandigar, Deli, Kanpur, ‘Chennaf, ‘Manali ] and Temperature =[15,22, 20, 26,2] 61 = pa.vatafrane({‘esty" + ['chanaigarh', “DeInt', “Kanpur : 1 “chennat", “Manali, Temperature’ 125, 22, 28, 26,-212) Print) printean) Whats the shape of dt etty = antretty") print ity Whats the type of city prantcetty) © chandigarn Intps:ifeolab rosearch google. com/drvaltgFLOIVZret76aTsD7eACRWOeNW_wuottontMode=tu sit1191728, 947 PM 10,,Pandas Assignment Day 10pynd - Colaboratory Create another datafeame 2 where the columns are ‘ety’ -[BengalaruColmbatore!SrrangamPondichesry] Temperature’ [24353639] “Tenperature’ + [24,35,3,38]}) print the shape of this datafame 2) ‘merge the two dataames together, save in a new dataframe named'83 63 = pauconcat(fet, a2}, axis = 0) © Changer © 2 Kanpur 2» 2 Strangam 36 3 Pondchenty 38 Select the part ofthe datatrame such that it contains cities wherer temp is less then or equal to 20 How mary cities are there? naa[[ctty' Temperature’ I] {B[ Temperature” ] <= 204([ Torpersture’ I Select the part ofthe datatrame such that contains the cties where tempearature greater than or equal to 35 al Terperature"] = 35 Intps:ifeolab rosearch google. com/érvaltgFLOIVZret76aTxD7gACRWCeNW_wuottontMode=tue ant119123, 947 PM 10,,Pandas Assignment Day 10pynd - Colaboratory Applying functions to columns and creating new columns We need o ereate another column in 3, which contains @ boolean value foreach city to incleste whether it's a union tertory oF not, + HINT: Chandigarh, Pondicherry and Delhi are only 3 union tetitris here cet is.wt(eity) oulist =f print(a) EF a mot in ["cnandtgarh', ut 21st. append(False) ut List-append(true) ue ots (ect Tinsel wetter = if a not fv ["Chandsgaeh’, “Pondicherry”, episee) = utilise 2 Kanpur 2» © Bongalan Py + Coimbatore 36 2 sorangam 36 [rrue, True, False, False, enh") 182 950 False, False, False, False, Trve] Intps:feolab roscarch google. com/érvaltgFLOIVZret76aTuD7eACRWCeNW_wuottorntMode=tue am1191728, 947 PM 10,,Pandas Assignment Day 10pynd - Colaboratory chty Temperature is_ut temp farentiet © Chansaarh 18 Te 0 + Dati 22 Te ns 3 henna 2 Fal 708 4 Nana 2 Fale ms 0 Bengatan 2 False 82 2 Sirangam 38 Fae 08 2 Pon ty 39 Tue 1022 ‘The temperatures mentioned in Temperature! column ate mentioned in Celsius, we need another column which contains the same In Fahrenhet, HN + Define a function ¢_t0_f which takes input temp in celsius and returns a value with temperature in Fahrenheit + To check: ¢-to_4(10) should return 50. ser C20 Ho) e213 ane = « te_f(cel) print(*%@.47 degrees Celsius Ss equivalent to 40.16 degrees Fahrenbeit™ X(ce1, fahe)) f check function «.te_#(18) fet eto. fle) pre tay e ‘ann = «.to_4(19) Print(*4l.37 degrees Celsius 4s equivalent to X9.1¢ degrees Fahrentest abn) fa list = fet « te.) #2 Gs hay 3 for x An dsl Temperature’) 4s et0-f0) fahr-Tset- append(¢) eal tenp_faremnser' [= fahe_Dist Intps:ifeolab roscarch google. com/érvaltgFLOIVZret76aTsD7gACRWCeNW_wuottontMode=tue ant1191728, 947 PM 10,,Pandas Assignment Day 10pynd - Colaboratory Indexing and selecting rows in DataFrame Select subset ofthe dataframe d1 such that it contains the cities which are union teritories 64 = eafas[ ts ue']e “ee at Incoxingiror ‘ssceback (nore recent call Ieee) “Spython-Anput-75-07Ce1649°259 40
srry at = sil esey"|-0e8,2,3] trames Jusr/ocal/1sb/pythons.£/s8st-packages/pandas/core/indexig py in validate key_length(seif, key) 790" def validate ey length(setf, key! Sequence[y]} -> Rone Jot Ge en(eey) > sett. nai 3 1B False Indexingerror("Too many andexers") 74 def _geriven tuple_sane-din(self, taps tuple) Selecta subset ofthe dataframe dl auch that it contains the etes which only have temperature above 90 Farenhiet, ft = e9[ast tenp_tarenhiet 996] Select only the ist three rows of the dataframe dl 4 A0ef 1,233] 3 Pontchery 8 Te 1022 Select all the rows and lat wo columns inthe datarame et Aoe{t:A{ts_ut', "tonp_farenhiet* 1] Groupby 1 create 2 catafrane using tctionary of your choice cata = pd.oataFrane( ane’: ['Ankit’, ‘Aishwarya', “Shaurya!, ‘Shivangi" Ty Age’ + 123, 21, 38, 21], University’ = [°BM, "OMI", “OU, “aMU'D, 29 oF = pa.batatrane(aata, colums-{ ‘Age’ }).sun() sen) Intps:ifeolab roscarch google. com/érvaltgFLOIVZret76aTsD7gACRWCeNW_wuottontMode=tuo ont119123, 947 PM 10,,Pandas Assignment Day 10pynd - Colaboratory ige 94 type: Snes 44 Use Groupby of single colton with angregste count) (2 = data. groupby([ "University" I)[Universsty']-e2unt() Use Groupby of single column with aggregate sin() and atx() #42 = data. groupby(("Age"})-s12e().groupby (Level-8) ax) (43 = data. groupby({ "University" ]).size()-grougby(leve ning) 44 Use Groupby of any 2 columns with a nea) (2 = data-groupby( ("Age") 988((°Age"* 'ne80"1)) ef2.colunms = [-abr_sean"] na nm m0 2» m0 Use Grouply of any 2 colums with aggregate sin() and max() 22's data. groupby( (Age, Mare" I).agg(Cage"? [nin "mae ]},(°Mave's (nin’, “aa D)) ef2.colums = ("age nin", "age sax stage ierst ag Page Covers min’, Snare ))oCAg8" Cain's mae) oniversity Age a) Data Range Create a pandas daterange where starting date is Tst of January.2020 and end dates 1st of April 2021, store it na new variable named’ 8 = pe.date_range(sta 2020-61-81", endo'2621-01-1") pinta Datetinerndex({'2022-01-01', "2020-01-02", "2020-01-05", "2020-01-64", Intps:ifeolab roscarch google. com/érvaltgFLOIVZret76aTsD7gACRWCeNW_wuottontMode=tuo sont119178, 947 Pat 10,,Pandas Assignment Day 10pynd - Colaboratory types‘datetinesa{ns]", lengthea57, freq'2") Whats the len of a? tents) Whats the ype ofa? eyeeta) Intps:ifeolab roscarch google. com/érvaltgFLOIVZret76aTsD7gACRWCeNW_wuottontMode=tuo wt
You might also like
Assignment Module 5
PDF
No ratings yet
Assignment Module 5
4 pages
Python Data Structure Assignment
PDF
No ratings yet
Python Data Structure Assignment
9 pages
NB 9
PDF
No ratings yet
NB 9
29 pages
NB 7
PDF
No ratings yet
NB 7
25 pages
Lab3 - Python - Pandas DataFrame - GeeksforGeeks
PDF
No ratings yet
Lab3 - Python - Pandas DataFrame - GeeksforGeeks
20 pages
NB 14
PDF
No ratings yet
NB 14
15 pages
DS Unit 3 Part 1
PDF
No ratings yet
DS Unit 3 Part 1
27 pages
Unit 4 Fod
PDF
100% (1)
Unit 4 Fod
21 pages
Machine Learnin
PDF
100% (2)
Machine Learnin
23 pages
W3school Numpy
PDF
No ratings yet
W3school Numpy
9 pages
Week 4 All Grpa
PDF
No ratings yet
Week 4 All Grpa
6 pages
Unit II Visualizing Using Matplotlib
PDF
No ratings yet
Unit II Visualizing Using Matplotlib
24 pages
PYTHON Assignment
PDF
No ratings yet
PYTHON Assignment
11 pages
Tableau Lab Manual
PDF
No ratings yet
Tableau Lab Manual
6 pages
Assignment 1 Data Type
PDF
No ratings yet
Assignment 1 Data Type
3 pages
10 Min Pandas
PDF
No ratings yet
10 Min Pandas
18 pages
Ad3301 Dev Full Notes
PDF
No ratings yet
Ad3301 Dev Full Notes
53 pages
Python Assignment
PDF
No ratings yet
Python Assignment
2 pages
ML Lab6.Ipynb - Colaboratory
PDF
100% (1)
ML Lab6.Ipynb - Colaboratory
5 pages
Module 6 Regular Expressions Assignment
PDF
No ratings yet
Module 6 Regular Expressions Assignment
2 pages
Module 2 Data Types, Operators, Variables Assignment
PDF
No ratings yet
Module 2 Data Types, Operators, Variables Assignment
4 pages
CCS355 Neural Networks and Deep Learning Lab
PDF
No ratings yet
CCS355 Neural Networks and Deep Learning Lab
43 pages
Exploratory Data Analysis (Eda) With Pandas: (Cheatsheet)
PDF
No ratings yet
Exploratory Data Analysis (Eda) With Pandas: (Cheatsheet)
7 pages
Assignment 61
PDF
100% (2)
Assignment 61
4 pages
Car Data
PDF
No ratings yet
Car Data
16 pages
Capstone Project 2 1
PDF
No ratings yet
Capstone Project 2 1
3 pages
Practical No-2
PDF
No ratings yet
Practical No-2
4 pages
Tutorial 2 - Clustering
PDF
100% (2)
Tutorial 2 - Clustering
6 pages
NumPy Notes
PDF
No ratings yet
NumPy Notes
13 pages
Python Function Questions
PDF
No ratings yet
Python Function Questions
13 pages
Unit 1
PDF
100% (1)
Unit 1
69 pages
Great Learning Notes
PDF
No ratings yet
Great Learning Notes
1 page
DL Lab Manual
PDF
100% (1)
DL Lab Manual
35 pages
New OOPS Assignment 1
PDF
No ratings yet
New OOPS Assignment 1
4 pages
1 - Write A Python Program To Check That A String Contains Only A Certain Set of Characters (In This Case A-Z, A-Z and 0-9)
PDF
0% (1)
1 - Write A Python Program To Check That A String Contains Only A Certain Set of Characters (In This Case A-Z, A-Z and 0-9)
4 pages
Python Numpy (1) : Intro To Multi-Dimensional Array & Numerical Linear Algebra
PDF
100% (1)
Python Numpy (1) : Intro To Multi-Dimensional Array & Numerical Linear Algebra
27 pages
FDS Lab Manual
PDF
No ratings yet
FDS Lab Manual
48 pages
Typecasting in Python
PDF
No ratings yet
Typecasting in Python
6 pages
Lab Session 06: Perform Following Operations Using Pandas
PDF
No ratings yet
Lab Session 06: Perform Following Operations Using Pandas
5 pages
Data Visualization
PDF
No ratings yet
Data Visualization
9 pages
Data Handling Using Pandas-1
PDF
No ratings yet
Data Handling Using Pandas-1
25 pages
Assignment Dict For Python
PDF
No ratings yet
Assignment Dict For Python
6 pages
1 Pandas Basics
PDF
No ratings yet
1 Pandas Basics
13 pages
Ge - Computer Science Data Analysis
PDF
No ratings yet
Ge - Computer Science Data Analysis
16 pages
ML Project Report: (Text Learning Case Study)
PDF
No ratings yet
ML Project Report: (Text Learning Case Study)
9 pages
Numpy - Tutorial - Ipynb - Colaboratory
PDF
No ratings yet
Numpy - Tutorial - Ipynb - Colaboratory
9 pages
Data Science PPT PD41
PDF
100% (1)
Data Science PPT PD41
8 pages
Pandas Guide
PDF
No ratings yet
Pandas Guide
64 pages
EDA With Pandas
PDF
No ratings yet
EDA With Pandas
8 pages
Assignment 2 Oops
PDF
No ratings yet
Assignment 2 Oops
10 pages
ML Unit Ii
PDF
No ratings yet
ML Unit Ii
30 pages
Chapter 4 File Handlinf Final (New)
PDF
100% (1)
Chapter 4 File Handlinf Final (New)
78 pages
Python Data Science
PDF
No ratings yet
Python Data Science
25 pages
Artificial Intelligence Lab Manual: Python
PDF
No ratings yet
Artificial Intelligence Lab Manual: Python
15 pages
Image Processing
PDF
No ratings yet
Image Processing
5 pages
Python Assignment
PDF
No ratings yet
Python Assignment
7 pages
Statistics Assignemt
PDF
100% (1)
Statistics Assignemt
19 pages
Lecture Notes: Introduction To Data Science and Big Data
PDF
No ratings yet
Lecture Notes: Introduction To Data Science and Big Data
5 pages
Curse of Dimensionality
PDF
No ratings yet
Curse of Dimensionality
9 pages
MCQ Questions
PDF
No ratings yet
MCQ Questions
8 pages
Classification and Prediction
PDF
No ratings yet
Classification and Prediction
126 pages
Linear Reg 1
PDF
No ratings yet
Linear Reg 1
7 pages
Life Expectancy Data
PDF
No ratings yet
Life Expectancy Data
288 pages
Car Details From Car Dekho
PDF
No ratings yet
Car Details From Car Dekho
212 pages
EDA Assignment
PDF
No ratings yet
EDA Assignment
16 pages
Zivame Planning Analyst Excel SQL Test
PDF
No ratings yet
Zivame Planning Analyst Excel SQL Test
50 pages
New - SQL Qustions
PDF
No ratings yet
New - SQL Qustions
3 pages
Project
PDF
No ratings yet
Project
18 pages
Untitled Spreadsheet
PDF
No ratings yet
Untitled Spreadsheet
3 pages