Pandas_QAs_A01


Q1. What do the two parts of the snippet above, on the left and on the right of the assignment operator ( = ) do?
Ans1. The part of the snippet on the right namely, pd.read_csv('http://bit.ly/uforeports') reads in the data, while the part on the left, namely, ufo saves the data under the variable name ufo


Q2. How are the two lines of code above connected to each other?
Ans2. The first line  "import pandas as pd" is essential for the second line of code to work. In the absence of the first line  "import pandas as pd" there will be a Name Error - name 'pd' is not defined (see below)
Q3. What library function of pandas is used by python 3 for reading in uforeports into the pandas DataFrame?
Ans3. The .read_csv() (( dot read underscore csv )) is the library function to read in csv files


Q4. What does the above snippet ufo.tail(1) do?
Ans4. The piece of code ufo.tail(1) shows the very last line of code in the uforeports dataframe?

Q5. What is the row index number written to the left of City name "Ybor"?
Ans5. The row index number is 18240.


Q6. What is the row index number next to  the City name "Eagle River"?
Ans6. The row index number  is 18239.

Q7. Now we have 3 lines of code here. What are the row index numbers given by code ufo.tail(2)?
Ans7. The indices of the rows given by code ufo.tail(2) are 18239 and 18240


Q8. How is the snippet ufo.tail(2) different from the snippet from ufo.tail(1)
Ans8. The snippet ufo.tail(2) displays the bottom 2 rows while ufo.tail(1) displays only the bottom row.   


Q9. What are the row indices produced by the following snippets: 
(i) ufo.head(1) 
(ii) ufo.tail(1)
(iii) ufo.head(2)
(iv) ufo.tail(2)
(v) ufo.head(4)
(vi) ufo.head(5) 

Ans9. 
(i) ufo.head(1)   => index 0 
(ii) ufo.tail(1)     => index 18240 
(iii) ufo.head(2)  => indices 0 and 1
(iv) ufo.tail(2)    => indices 18239 and 18240
(v) ufo.head(4)   => indices 0, 1, 2 and 3
(vi) ufo.head(5)  => indices 0, 1, 2, 3 and 4





Q10. How many rows would there be produced by the following snippets, say whether they are the top or the bottom rows.
(i) ufo.head(11) 
(ii) ufo.tail(3)
(iii) ufo.head(101)
(iv) ufo.tail(4)
(v) ufo.head(99)
(vi) ufo.head(999) 

Ans10. 
(i) ufo.head(11)   => The topmost 11 rows
(ii) ufo.tail(3)     =>  The bottommost 3 rows 
(iii) ufo.head(101)  => The topmost 101 rows
(iv) ufo.tail(4)    =>  The bottommost 4 rows 
(v) ufo.head(99)   =>  The topmost 99 rows
(vi) ufo.head(999)  =>  The topmost 999 rows




No comments:

Post a Comment