PYTHON PANDAS - I Viva

Q.1What is Pandas/Python pandas ?
Ans. Pandas is a Python library package that has robust features. It is very fast, flexible, and expressive data structures designed to make working with “relational” or “labeled” data both easy.
Q.2 What is Python Pandas used for ?
Ans. Pandas is a software library written for the Python programming language for data manipulation and analysis. In particular, it offers data structures and operations for manipulating numerical tables and time series. Pandas is free software released under the three-clause BSD license.
Q.3 Mention the different types of Data Structures in Pandas.
Ans. Pandas provides two basic data structures, which are supported by the Pandas library, Series, and DataFrames. Both of these data structures are built on top of the NumPy. It also provides a multi-dimensional structure Panel.
Q.4 What is Series in Pandas ?
Ans. It is a feature that is a one-dimensional labelled array capable of holding data of any type (integer, string, float, python objects, etc.). It is nothing but like a column in
Q.5 What is DataFrame in Pandas ?
Ans. It is a pandas feature which is a 2-dimensional labelled data structure with columns of potentially different types. As an example, it is like a spreadsheet or SQL table, or a dict of Series objects.
Q.6 What is the main difference between a Pandas Series and a single-column DataFrame in Python ?
Ans. Series is size immutable while DataFrame even with single column is size mutable. However, both are value mutable.
Q.7 Define Reindexing.
Ans. Reindexing is used to change the index of the rows and columns of the DataFrame. We can reindex the single or multiple rows by using the reindex) method. Default values in the new index are assigned NaN if it is not present in the DataFrame.
Q.8 How would you add an Index, to a Pandas DataFrame ?
Ans. Pandas allows adding the inputs to the index argument if we create a DataFrame. It will make sure that we have the desired index. If we don’t specify inputs, the DataFrame will contain, by default, a numerically valued index that starts with 0 and ends on the last row of the DataFrame.
Q.9 How would you add a row to a Pandas DataFrame ?
Ans. We can use loc and iloc to insert the rows in the DataFrame.
The loc basically works for the labels of our index. It can be understood as if we insert in loc(4], which means we are looking for that values of DataFrame that have an index labeled 4. The iloc basically works for the positions in the index. It can be understood as if we insert in iloc(41, which means we are looking for the values of DataFrame that are present at index ‘4’.
Q.10 How would you add a column to a Pandas DataFrame ?
Ans. If we want to add the column to the DataFrame, we can easily follow the same procedure as adding an index to the DataFrame by using loc or iloc.
Q.11 How would you delete Indices from a Pandas DataFrame ?
Ans. To remove the index from the DataFrame, we should execute the statement del df.index.name.
Q.12 How would you drop a row or column of DataFrame ?
Ans. We can use the drop() method for deleting a row or a column from the DataFrame. The axis argument that is passed to the drop() method is either 0 if it indicates the rows and 1 if it drops the columns.
Q.13 How would you rename the index or columns of a Pandas DataFrame ?
Ans. We can use the rename method to give different values to the columns or the index values of DataFrame.
Q.14 How to iterate over a Pandas DataFrame ?
Ans. We can iterate over the rows of the DataFrame by using for loop in
combination with an iterrows) call on the DataFrame.
Q.15 What is NumPy array ?
Ans. Numerical Python (Numpy) is defined as a Python package used for performing the various numerical computations and processing of the multidimensional and single-dimensional array elements. The calculations using Numpy arrays are faster than the normal Python array or list.
Q.16 What is the difference between loc and iloc ?
Ans. loc gets rows (or columns) with particular labels from the index. iloc gets rows (or columns) at particular positions in the index (so it only takes integers).
Q.17 What are negative indexes and why are they used ?
Ans. The sequences in Python are indexed and it consists of the positive as well as negative numbers. The numbers that are positive uses ‘O’ that is used as the first index and ‘1’ as the second index and the process goes on like that. The index for the negative number starts from ‘-1′ that represents the last index in the sequence and’-2′ as the penultimate index and the sequence carries forward like the positive number.
Q.18 What is matplotlib ?
Ans. matplotlib is a plotting library for the Python programming language and its numerical mathematics extension NumPy.

Q.19 What is histogram? How is it different from a bar chart ?

Ans. Bar charts are for discrete data and hence bars are distinct, i.e., there are gaps between bars. Histograms are either continuous (height) or grouped discrete data and thus, they don’t have gaps between the bars.

Q.20 How is reindexing useful ?

Ans. The indexes are used for accessing a row or a column from a dataframe. In different applications, one might need to access the data with a different index with a different order, meaningful in that context. For such needs, reindexing proves useful and allows us to change the indexes of a dataframe using reindex).

Q.21 How are reindex() and reindex-like ) similar and different ?

Ans. The reindex) method can specify the new order of existing indexes and
column labels, and/or also create new indexes/column labels.
The reindex like() method is used for creating indexes/column-labels based on other dataframe object.
Q.22 Name some commonly used chart types.

Ans. Some commonly used chart types are line chart, bar chart, pie chart, scatter chart etc.

Q.23 What is the role of legends in a graphlchart ?

Ans. A Legend is a representation of keys or entries on the plotted area of chart or graph which are linked to the data table of the chart or graph. These are the different colors that identify different sets of data plotted on the plot. The legends are shown in a corner of the plot.

Q.24 When should you create histograms and when should you create bar charts to present data visually ?

Ans. Histograms are used to show distributions of variables while bar charts are used to compare variables.
Histograms plot continuous quantitative data with ranges of the data grouped into bins or intervals while bar charts plot categorised data.

Q.25 Name some common data structures of Python’s Pandas library.

Ans. Three basic data structures of Python Pandas are :
– Series
– DataFrame
– Panel

Q.26 What is the difference between iloc and loc with respect to a DataFrame ?
Ans. With loc, both start label and end label are included when given as start end, butwith iloc, like slices end index/position is excluded when given as start : end.
Q.27 What is the difference between iat and at with respect to a DataFrame ?
Ans. The at and iat attributes are used to access single values at specific location in a dataframe while at uses row and column labels, the iat attribute uses integer position to access the value.
Q.28 How does Python support data visualization ?
Ans. For data visualization in Python, the Matplotlib library’s Pyplot interface is used. Python also makes available many other libraries for data visualisation such as Plotly, Seaborn etc.
Q.29 What is a CSV file ?
Ans. The acronym CSV is short for Comma-Separated Values, which refers to a tabular data saved as plain text where data values are separated by commas.
Q.30 What are advantages of CSV file formats ?
Ans.
(i) CSV is a common format for data interchange.
(ii) It can be opened in popular spreadsheet packages like MS-Excel, Calc etc.
Q.31 What all libraries do you require in order to bring data from a CSV file into a dataframe ?
Ans. Python’s Pandas library.
Q.32 Name two functions provided by Pandas library that help you read and write to CSV files from Python code.
Ans. read_csv() for reading from a cs file from within Python code and to_csv() for writing onto a cs file from within Python code.
Q.33 Which Pandas’ data structure does the read_su() function read the data into?
Ans. DataFrame
Q.34 While reading from a cso file using read _csu() into a dataframe, what argument will you add so that the first row is not used as the column headings ?
Ans. To supress first row as header, the additional argument will be :
header = None
Q.35 How is Series data structure different from a DataFrame data structure ?
Ans. A Series is a one-dimensional object that can hold any data type such as integers, floats and strings. It has only one axis (maxis = 0). A DataFrame is a two-dimensional object that can have columns with potential different types. A dataframe can be created different kind of inputs which may include dictionaries, lists, series, and even another DataFrame. Individual columns of a dataframe can act as separate Series objects. It is the most commonly used Pandas object. It has two axes (axis 0 and axis 1).
Q.36 If you have a dataframe having a single column then isn’t it the same as a Series object, which is one-dimensional?
Ans. A dataframe having a single column may look same as a Series object but there is a key difference. As both the Series and the dataframe data structures are value mutable (can be changed), but dataframe is size mutable while Series is size immutable.
Thus, even though both the Series object and a dataframe object with single column appear the same, they behave differently when their size is changed.
 

Leave a Reply

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

sign up!

We’ll send you the hottest deals straight to your inbox so you’re always in on the best-kept software secrets.