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)
191 views
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 now
Download
Save Pandas Assignment For Later
Download
Save
Save Pandas Assignment For Later
100%
100% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
100%
(2)
100% found this document useful (2 votes)
191 views
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 now
Download
Save Pandas Assignment For Later
Carousel Previous
Carousel Next
Save
Save Pandas Assignment For Later
100%
100% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
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
Python Assignment
PDF
No ratings yet
Python Assignment
2 pages
NumPy Notes
PDF
No ratings yet
NumPy Notes
13 pages
Python Hands On Answers
PDF
No ratings yet
Python Hands On Answers
15 pages
Python Assignment
PDF
No ratings yet
Python Assignment
7 pages
Python MCQ-10 (Ques)
PDF
No ratings yet
Python MCQ-10 (Ques)
2 pages
Python Data Structure Assignment
PDF
No ratings yet
Python Data Structure Assignment
9 pages
Project
PDF
No ratings yet
Project
18 pages
DL Lab Manual
PDF
100% (1)
DL Lab Manual
35 pages
Unit 1
PDF
100% (1)
Unit 1
69 pages
FDS Lab Manual
PDF
No ratings yet
FDS Lab Manual
48 pages
New OOPS Assignment 1
PDF
No ratings yet
New OOPS Assignment 1
4 pages
Unit II Visualizing Using Matplotlib
PDF
No ratings yet
Unit II Visualizing Using Matplotlib
24 pages
Assignment 2 Oops
PDF
No ratings yet
Assignment 2 Oops
10 pages
Machine Learning
PDF
100% (5)
Machine Learning
56 pages
Exploratory Data Analysis (Eda) With Pandas: (Cheatsheet)
PDF
No ratings yet
Exploratory Data Analysis (Eda) With Pandas: (Cheatsheet)
7 pages
Numpy - Tutorial - Ipynb - Colaboratory
PDF
No ratings yet
Numpy - Tutorial - Ipynb - Colaboratory
9 pages
ML Lab Observation
PDF
100% (1)
ML Lab Observation
44 pages
Artificial Intelligence Lab Manual: Python
PDF
No ratings yet
Artificial Intelligence Lab Manual: Python
15 pages
Machine Learnin
PDF
100% (2)
Machine Learnin
23 pages
PYTHON Assignment
PDF
No ratings yet
PYTHON Assignment
11 pages
21 Machine Learning Using Scikit Learn Ipynb Colaboratory PDF
PDF
100% (1)
21 Machine Learning Using Scikit Learn Ipynb Colaboratory PDF
23 pages
Python Practice Problems List
PDF
No ratings yet
Python Practice Problems List
4 pages
Tutorial 2 - Clustering
PDF
100% (2)
Tutorial 2 - Clustering
6 pages
PYTHON Notes Unit1&Unit2
PDF
No ratings yet
PYTHON Notes Unit1&Unit2
38 pages
Chandigarh Group of Colleges College of Engineering Landran, Mohali
PDF
No ratings yet
Chandigarh Group of Colleges College of Engineering Landran, Mohali
47 pages
Pandas Practice Questions
PDF
No ratings yet
Pandas Practice Questions
2 pages
Unit V Data Visualization
PDF
No ratings yet
Unit V Data Visualization
49 pages
NB 14
PDF
No ratings yet
NB 14
15 pages
Assignment 1 Data Type
PDF
No ratings yet
Assignment 1 Data Type
3 pages
Unit 5
PDF
No ratings yet
Unit 5
27 pages
Ad3311 - Artificial Intelligence Lab Manual
PDF
No ratings yet
Ad3311 - Artificial Intelligence Lab Manual
30 pages
Fds Unit - III
PDF
No ratings yet
Fds Unit - III
58 pages
PYTHON FOR DS EVALUATION QUIZ
PDF
No ratings yet
PYTHON FOR DS EVALUATION QUIZ
23 pages
Walmart Sales Prediction
PDF
No ratings yet
Walmart Sales Prediction
21 pages
Data Mining Project
PDF
No ratings yet
Data Mining Project
33 pages
Data Analysis and Visualisation With Python
PDF
No ratings yet
Data Analysis and Visualisation With Python
75 pages
Assignment # 01 Bscs - 7 Semester: Machine Learning
PDF
100% (1)
Assignment # 01 Bscs - 7 Semester: Machine Learning
5 pages
Ad3301 Dev Full Notes
PDF
No ratings yet
Ad3301 Dev Full Notes
53 pages
SVM (Support Vector Machine) For Classification - by Aditya Kumar - Towards Data Science
PDF
100% (1)
SVM (Support Vector Machine) For Classification - by Aditya Kumar - Towards Data Science
28 pages
Unit 4
PDF
No ratings yet
Unit 4
60 pages
ML Lab6.Ipynb - Colaboratory
PDF
100% (1)
ML Lab6.Ipynb - Colaboratory
5 pages
Tableau Lab Manual
PDF
No ratings yet
Tableau Lab Manual
6 pages
Module 5 Pandas Assignment Updated
PDF
No ratings yet
Module 5 Pandas Assignment Updated
3 pages
MCQ Questions
PDF
No ratings yet
MCQ Questions
8 pages
AIML Lab Manual
PDF
No ratings yet
AIML Lab Manual
43 pages
UpGrad Python Practice Question
PDF
No ratings yet
UpGrad Python Practice Question
2 pages
Decision Tree
PDF
No ratings yet
Decision Tree
12 pages
DS+C25 PGDDS+Masters
PDF
No ratings yet
DS+C25 PGDDS+Masters
13 pages
CCS355 Neural Networks and Deep Learning Lab
PDF
No ratings yet
CCS355 Neural Networks and Deep Learning Lab
43 pages
Supervised Learning
PDF
No ratings yet
Supervised Learning
3 pages
Machine Learning Notes
PDF
No ratings yet
Machine Learning Notes
6 pages
ML Practical File
PDF
100% (2)
ML Practical File
43 pages
Machine Learning Mini-Project Report
PDF
No ratings yet
Machine Learning Mini-Project Report
26 pages
Pandas in Python 16sept2022
PDF
No ratings yet
Pandas in Python 16sept2022
8 pages
ML Lab
PDF
No ratings yet
ML Lab
21 pages
Import As
PDF
100% (1)
Import As
27 pages
Bank Customer Churn Analysis - Jupyter Notebook
PDF
No ratings yet
Bank Customer Churn Analysis - Jupyter Notebook
11 pages
Assignment Module 5
PDF
No ratings yet
Assignment Module 5
4 pages
10 Min Pandas
PDF
No ratings yet
10 Min Pandas
18 pages
64[6]
PDF
No ratings yet
64[6]
5 pages
New - SQL Qustions
PDF
No ratings yet
New - SQL Qustions
3 pages
Zivame Planning Analyst Excel SQL Test
PDF
No ratings yet
Zivame Planning Analyst Excel SQL Test
50 pages
Car Details From Car Dekho
PDF
No ratings yet
Car Details From Car Dekho
212 pages
Untitled Spreadsheet
PDF
No ratings yet
Untitled Spreadsheet
3 pages
Life Expectancy Data
PDF
No ratings yet
Life Expectancy Data
288 pages
Car Data
PDF
No ratings yet
Car Data
16 pages
Linear Reg 1
PDF
No ratings yet
Linear Reg 1
7 pages
Statistics Assignemt
PDF
100% (1)
Statistics Assignemt
19 pages
EDA Assignment
PDF
No ratings yet
EDA Assignment
16 pages