December 30, 2021

Top 20 Apache Tapestry Interview Questions and Answers

 

                Do you want to succeed in the Apache Tapestry and advance your career? Then, on this page, we will offer you with the complete set of Apache Tapestry job Interview Questions and Answers. Apache Tapestry is a Java-based open source web framework. It's a web framework that's built around components. Apache Tapestry is a framework for building extremely scalable web applications. Many top firms offer Apache Tapestry jobs in a variety of positions. In the Java programming language, there are more opportunities for experienced workers. Job hunting may be difficult and exhausting, especially if you don't know how to apply, where to look, or how to prepare for job interviews. To minimise any misunderstanding, we've framed Apache tapestry job interview questions and answers to help you prepare for your interview.

 Apache Hive Interview Questions & Answers

Ques. 1): How do I run multiple Tapestry applications in the same web application?

Answer:

Multiple Tapestry 5 apps are not supported; there is only one place to identify the application root package, therefore configuring multiple filters into multiple directories isn't an option.

Tapestry 5 did not include support for numerous Tapestry applications in the same web application (it needlessly complicated Tapestry 4). Given how disjointed Tapestry 5 pages are, there doesn't appear to be a benefit to doing so... and, if it were possible, there would be a considerable drawback in terms of memory use.

You can run Tapestry 4 and Tapestry 5 apps side by side (the package names are different for this reason), but they have no knowledge of each other and are unable to interact directly. This is just like the way you could have a single WAR with multiple servlets; the different applications can only communicate via URLs, or shared state in the HttpSession.

 Apache Ambari interview Questions & Answers

Ques. 2): Tapestry focuses on the wrong field in my form, how do I fix that?

Answer:

Tapestry usually determines which field in your form should receive initial emphasis by giving a FieldFocusPriority to each field as it renders, which translates to the following logic:

There is an error in the first field.

Alternatively, the first mandatory field

Alternatively, the first field

Due to a variety of reasons beyond Tapestry's control, its choices may not always be exactly what you desire, necessitating the use of an override. The data is kept track of in the JavaScriptSupport environment. It's simply a matter of injecting the component to get its client id, then notifying JavaScriptSupport of your override.

Here's an example

 <t:textfield t:id="email" t:mixins="OverrideFieldFocus" .../>

The OverrideFieldFocus mixin forces the email field to be the focus field, regardless.

 Apache NiFi Interview Questions & Answers

Ques. 3): Is Tapestry A Jsp Tag Library?

Answer :

Tapestry is not a JSP tag library; it is based on the servlet API but does not make use of JSPs. It has its own rendering engine and HTML template format. Tapestry now offers a simple JSP tag library in release 3.0, allowing JSP pages to link to Tapestry pages.

Apache Spark Interview Questions & Answers

Ques. 4): I Have A Form With A Submit Button. On The Form And The Submit Button Are Two Separate Listeners. Which Is Invoked First?

Answer :

While the shape encounters your button at some time throughout the rewind, the button's listener must be called. The form's submitListener must be called after the shape has completed its rewind, therefore different listeners were called in either scenario. Note that this could mean that the listener for a button can be called before the form has'submitted' all of its values; it all depends on where your input fields are in relation to your button.

 

Ques. 5): Is There A Wysiwyg Editor For Tapestry, Or An Ide Plugin?

Answer :

Tapestry currently lacks a WYSIWYG editor; nonetheless, the nature of Tapestry allows existing editors to function reasonably well (Tapestry additions to the HTML markup are virtually invisible to a WYSIWYG editor). Spindle is a Tapestry plugin for the Eclipse IDE, which is free and open-source. Tapestry apps, pages, and components may now be created using wizards and editors.

 

Ques. 6): How Is The Performance Of Tapestry?

Answer :

Other testing (recorded in the Tapestry discussion boards) coincides with my own testing, which was published in the September 2001 issue of the Java Report: Although plain JSPs have a minor advantage in demo applications, performance curves for equal Tapestry and JSP applications with a database or application server backend are identical. Consider the performance of your Java developers rather than the performance of Tapestry.

 

Ques. 7): What’s The Lifecycle Of A Form Submit?

Answer :

Events will trigger in the following order:

initialize()

pageBeginRender()

formListenerMethod()

pageBeginRender()

The form "rewind" cycle is simply a render cycle with the output buffered and scraped instead of being written to the servlet output stream. The second pageBeginRender() is called while the page is being rendered. To distinguish between these two render cycles, use requestCycle.isRewinding().

 

Ques. 8): Does Tapestry Work With Other Other Application Servers Besides Jboss?

Answer :

Yes, of course! For the turn-key demonstrations, JBoss is free and convenient. In less than a minute, you can download Tapestry and JBoss and have a real J2EE application running! JBoss configuration scripts are specific to a specific release of JBoss, which must be 3.0.6. Tapestry apps, on the other hand, are completely container agnostic... Tapestry is unconcerned with the servlet container it's in, and it doesn't even require an EJB container.

 

Ques. 9): Can I Use The Same Component Multiple Times In One Template?

Answer:

No – but you can copy the definition of a component pretty easily.

<component id=”valueInsert” type=”Insert” >

 <binding name=”value” expression=”getValueAt( rowIndex, columnIndex )” />

 </component>

<component id=”valueInsert1″ copy-of=”valueInsert”/>

 <component id=”valueInsert2″ copy-of=”valueInsert”/>

 <component id=”valueInsert3″ copy-of=”valueInsert”/>

 <component id=”valueInsert4″ copy-of=”valueInsert”/>

 

Ques. 10): Why is @script required in Apache Tapestry?

Answer:

The script framework is a useful tool for grouping scripts into components. It delivers the benefits of components to scripts. It may now be utilised as a component without having to bother about renaming field names or rewiring the fields and scripts. All you have to do now is declare the component and you're ready to go. It is true that another layer of abstraction must be acquired, but once learned, it is extremely powerful. And, to tell you the truth, there isn't much to it.

The script framework is required since form element/field names are produced automatically by the framework. As a result, you write your script in XML, assigning these names to variables, and relying on the framework to deliver the correct names at runtime. Further, you can request that the framework include extra objects that will aid in the creation of your script.

 

Ques. 11): When a form is submitted, why does Tapestry send a redirect?

Answer:

This is a variant of the Post/Redirect/Get strategy. It ensures that if a user resubmits the resultant page after an operation that alters server-side state, such as a form submission, the operation is not repeated; instead, only the results of the operation, reflecting the updated server-side state, are re-rendered.

This has the unwelcome consequence of requiring any data required to produce the answer to persist between the event request (the form submission) and the render request; this frequently necessitates the use of @Persist annotations on fields.

 

Ques. 12): When I utilise an HTML object like &nbsp; in my template, why do I get a SAXParseException?

Answer:

Tapestry reads your templates using a regular SAX parser. This means that your templates must be well-formed, with balanced open and close tags, quoted attribute values, and defined entities. The simplest method to do this is to include a DOCTYPE at the top of your template:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

Part of the DOCTYPE is the declaration of entities such as &nbsp;.

You can also use the numeric version: &#160; This is the exact same character and will render in the browser identically. When no doctype is present, Tapestry adds an XHTML doctype; this ensures that common HTML entities behave properly.

 

Ques. 13): When I submit a form, I get an error message that says "Tapestry is undefined." Why?

Answer:

This client-side mistake is obvious, yet it can be difficult to resolve. It implies your browser was unable to correctly load the tapestry.js file. Why, exactly, is the question? It could be for a variety of causes, some of which are listed below:

Check to see if 'tapestry.js' is present in the head section of your HTML page.

Tapestry generates a single URL to get all the JS files if the tapestry.combine-scripts configuration parameter is set to true. This can sometimes result in long URLs that browsers are unable to get. Set the sign to false and see what happens.

If you use jQuery in conjunction with Tapestry's prototype, the '$' selection used by both will clash. Put jQuery on top of the stack and enable the jQuery.noConflict mode in this scenario.

Also, if you've added a custom or third-party JS library to the stack and it's causing the JavaScript parsing to fail, look at the JavaScript syntax in that library.

If you used a programme to compress your JavaScript libraries, it's possible that you'll get JavaScript syntax issues, so make sure it works with all of the JavaScript files unpacked.

 

Ques. 14): Do I have to specify both id and t:id for Zone components?

Answer:

The Zone component's examples (in the Component Reference) always give both id and t:id, which is definitely a good thing.

In general, the client-side id (the id attribute) will be the same as the Tapestry component id if you don't define it (t:id).

There are, however, numerous exceptions to this rule. It's possible that the Zone is rendering inside a Loop (in which case, each rendering will have a unique client side id). A random unique id is added into the id if the Zone is rendering as part of a partial page render. Tapestry component ids in nested components can potentially clash in other situations.

 

Ques. 15): When rendering an empty Zone, why do I get the exception "The produced content did not include any components that allow for the positioning of the concealed form field's element."?

Answer:

Tapestry must write a hidden input element with information needed when the form is submitted as part of its form processing. Because the content of a Zone can be altered or erased, a hidden field separate from the rest of the enclosing form is established solely for the Zone.

At the same time, Tapestry wants to position the <input> field in a valid location, and HTML defines some constraints for that; an input field must appear inside a <p> or <div> element. If your zone is initially empty, there's no place to put the hidden element, and Tapestry will complain.

The solution is simple: just add a <div> element to the body of the zone. This ensures that there's a place for the hidden input field.  An empty <div> element (even one containing a hidden form field) will not affect page layout.

 

Ques. 16): Why is it necessary for me to provide an interface for my services? Why can't I simply use the class?

Answer:

To begin with, you can do just this, but you will lose some of the functionality provided by Tapestry's IoC container.

Tapestry will be able to provide functionality for your service around the core service implementation as a result of the split. This is accomplished by using proxies, which are Java classes that implement the service interface. The proxy's methods will eventually call the methods of your service implementation.

One of the most important functions of proxies is to encapsulate the life cycle of a service: most services are singletons that are built just once. Just in time refers to the moment you call a method. What's going on is that the life cycle proxy (the object that gets injected into pages, components or other service implementations) checks on each method invocation to see if the actual service exists yet. If not, it instantiates and configures it (using proper locking to ensure thread safety), then delegates the method invocation to the service.

If you bind a service class (not a service interface and class), then the service is fully instantiated the first time it is injected, rather than at that first method invocation. Further, you can't use decorations or method advice on such a service. The life cycle proxy (the object injected into pages, components, and other service implementations) examines each method invocation to determine if the actual service has been created yet. If it isn't already instantiated and configured (with suitable locking to ensure thread safety), it delegated method invocation to the service.

When you bind a service class (rather than a service interface and class), the service is fully instantiated the first time it is injected, rather than when the first method is invoked. Furthermore, such a service does not allow for the use of decorations or technique suggestions.

The final reason for the service interface / implementation split is to nudge you towards always coding to an interface, which has manifest benefits for code structure, robustness, and testability.

 

Ques. 17): How do I make my service startup with the rest of the application, rather than lazily?

Answer:

Tapestry services are designed to be lazy; they are only fully realized when needed: when the first method on the service interface is invoked.

Sometimes a service does extra work that is desirable at application startup: examples may be registering message handlers with a JMS implementation, or setting up indexing. Since the service's constructor (or @PostInjection methods) are not invoked until the service is realized.

The solution is the @EagerLoad annotation; service implementation classes marked with this annotation are loaded when the Registry is first startup, rather than lazily.

 

Ques. 18): How can I dynamically add new components to an existing page?

Answer:

You don't, to put it succinctly. The long answer is that you don't have to in order to achieve the desired behaviour.

High scalability is one of Tapestry's core values; it can be expressed in a variety of ways, reflecting scalability concerns both within a single server and across a cluster of servers.

Although you code Tapestry pages and components as if they were ordinary POJOs (Plain Old Java Objects — Tapestry doesn't require you to extend any base classes or implement any special interfaces), they behave more like a traditional servlet when deployed by Tapestry: a single instance of each page serves requests from multiple threads. In the background,

 

Ques. 19): What this means is that any incoming request must be handled by a single page instance. Therefore, Tapestry enforces the concept of static structure, dynamic behavior.

Answer:

 Beyond simple conditionals and loops, Tapestry offers a variety of options for varying what content is presented. When rendering a page, you can "drag in" components from other pages (other FAQs will expand on this concept). The idea is that, while the structure of a Tapestry page is quite strict, the order in which the page's components render does not have to be top to bottom.

 

Ques. 20): Why do my images and stylesheets end up with a weird URLs like /assets/meta/zeea17aee26bc0cae/layout/layout.css?

Answer:

The servlet container isn't used by Tapestry to serve static assets (images, stylesheets, flash movies, etc.). Tapestry, on the other hand, handles the requests and streams assets to the browser.

The content of the assets will be compressed using GZIP (if the client supports compression, and the content is compressible). Tapestry will also add an expires header to the content in the future. This means the browser will not ask for the file again, resulting in a significant reduction in network traffic.

The strange hex string is a fingerprint; it's a hash code calculated from the asset's real content. If the asset changes, a new fingerprint will be created, as well as a new path and (immutable) resource. This approach, combined with a far-future expires header also provided by Tapestry, ensures that clients aggressively cache assets as they navigate your site, or even between visits.



Top 20 Python Pandas Interview Questions and Answers


            Pandas is a Python library that provides high-performance, easy-to-use data structures and data analysis tools for the Python programming language. It is open-source and BSD-licensed. Python with Pandas is utilised in a variety of academic and commercial disciplines, including finance, economics, statistics, analytics, and more. 

Data analysis necessitates a great deal of processing, such as restructuring, cleansing, or combining, among other things. Numpy, Scipy, Cython, and Panda are just a few of the quick data processing tools available. However, we favour Pandas since they are faster, easier, and more expressive than other tools.

 Python Interview Questions & Answers

Ques. 1): What is Pandas? What is the purpose of Python pandas?

Answer:

Pandas is a Python module that provides quick, versatile, and expressive data structures that make working with "relational" or "labelled" data simple and intuitive. Its goal is to serve as the foundation for undertaking realistic, real-world data analysis in Python.

Pandas is a data manipulation and analysis software library for the Python programming language. It includes data structures and methods for manipulating numerical tables and time series, in particular. Pandas is open-source software distributed under the BSD three-clause licence.

 

Ques. 2): Mention the many types of data structures available in Pandas?

Answer:

The pandas library supports two data structures: Series and DataFrames. Numpy is used to construct both data structures. In pandas, a Series is a one-dimensional data structure, while a DataFrame is a two-dimensional data structure. Panel is another axis label that is a three-dimensional data structure that comprises items, major axis, and minor axis.

 

Ques. 3): What are the key features of pandas library ? What is pandas Used For ?

Answer:

There are various features in pandas library and some of them are mentioned below

Data Alignment

Memory Efficient

Reshaping

Merge and join

Time Series

This library is developed in Python and can be used to do data processing, data analysis, and other tasks. To manipulate time series and numerical tables, the library contains numerous operations as well as data structures.

 

Ques. 4): What is Pandas NumPy?

Answer:

Pandas Numpy is an open-source Python module that allows you to work with a huge number of datasets. For scientific computing with Python, it has a powerful N-dimensional array object and complex mathematical methods.

Fourier transformations, linear algebra, and random number capabilities are some of Numpy's most popular features. It also includes integration tools for C/C++ and Fortran programming.

 

Ques. 5): In Pandas, what is a Time Series?

Answer:

An ordered sequence of data that depicts how a quantity evolves over time is known as a time series. For all fields, pandas has a wide range of capabilities and tools for working with time series data.

pandas supports:

Taking time series data from a variety of sources and formats and parsing it

Create a series of dates and time ranges with a set frequency.

Manipulation and conversion of date and time with timezone data

A time series is resampled or converted to a specific frequency.

Using absolute or relative time increments to do date and time arithmetic.

 

Ques. 6): In pandas, what is a DataFrame?

Answer:

Pandas DataFrame is a possibly heterogeneous two-dimensional size-mutable tabular data format with labelled axes (rows and columns). A data frame is a two-dimensional data structure in which data is organised in rows and columns in a tabular format. The data, rows, and columns are the three main components of a Pandas DataFrame.

Creating a Pandas DataFrame-

A Pandas DataFrame is built in the real world by loading datasets from existing storage, which can be a SQL database, a CSV file, or an Excel file. Pandas DataFrames can be made from lists, dictionaries, and lists of dictionaries, among other things. A dataframe can be constructed in a variety of ways.  

Creating a dataframe using List: DataFrame can be created using a single list or a list of lists.

 

Ques. 7): Explain Series In pandas. How To Create Copy Of Series In pandas?

Answer:

Series is a one-dimensional labeled array capable of holding any data type (integers, strings, floating point numbers, Python objects, etc.). The axis labels are collectively referred to as the index. The basic method to create a Series is to call:

>>> s = pd.Series(data, index=index), where the data can be a Python dict, an ndarray or a scalar value.

To create a copy in pandas, we can call copy() function on a series such that

s2=s1.copy() will create copy of series s1 in a new series s2.

 

Ques. 8): How will you create an empty DataFrame in pandas?

Answer:

To create a completely empty Pandas dataframe, we use do the following:

import pandas as pd

MyEmptydf = pd.DataFrame()

This will create an empty dataframe with no columns or rows.

To create an empty dataframe with three empty column (columns X, Y and Z), we do:

df = pd.DataFrame(columns=[‘X’, ‘Y’, ‘Z’])

 

Ques. 9): What is Python pandas vectorization?

Answer:

The process of executing operations on the full array is known as vectorization. This is done to reduce the number of times the functions iterate. Pandas has a number of vectorized functions, such as aggregations and string functions, that are designed to work with series and DataFrames especially. To perform the operations quickly, it is preferable to use the vectorized pandas functions.

 

Ques. 10):  range ()  vs and xrange () functions in Python?

Answer:

In Python 2 we have the following two functions to produce a list of numbers within a given range.

range()

xrange()

in Python 3, xrange() is deprecated, i.e. xrange() is removed from python 3.x.

Now In Python 3, we have only one function to produce the numbers within a given range i.e. range() function.

But, range() function of python 3 works same as xrange() of python 2 (i.e. internal implementation of range() function of python 3 is same as xrange() of Python 2).

So The difference between range() and xrange() functions becomes relevant only when you are using python 2.

range() and xrange() function values

a). range() creates a list i.e., range returns a Python list object, for example, range (1,500,1) will create a python list of 499 integers in memory. Remember, range() generates all numbers at once.

b).xrange() functions returns an xrange object that evaluates lazily. That means xrange only stores the range arguments and generates the numbers on demand. It doesn’t generate all numbers at once like range(). Furthermore, this object only supports indexing, iteration, and the len() function.

On the other hand xrange() generates the numbers on demand. That means it produces number one by one as for loop moves to the next number. In every iteration of for loop, it generates the next number and assigns it to the iterator variable of for loop.

 

Ques. 11):  What does categorical data mean in Pandas?

Answer:

Categorical data is a Pandas data type that correlates to a statistical categorical variable. A categorical variable is one that has a restricted number of possible values, which is usually fixed. Gender, country of origin, blood type, social status, observation time, and Likert scale ratings are just a few examples. Categorical data values are either in categories or np.nan.This data type is useful in the following cases:

It is useful for a string variable that consists of only a few different values. If we want to save some memory, we can convert a string variable to a categorical variable.

It is useful for the lexical order of a variable that is not the same as the logical order (“one”, “two”, “three”) By converting into a categorical and specify an order on the categories, sorting and min/max is responsible for using the logical order instead of the lexical order.

It is useful as a signal to other Python libraries because this column should be treated as a categorical variable.

 

Ques. 12): To a Pandas DataFrame, how do you add an index, a row, or a column?

Answer:

Adding an Index into a DataFrame: If you create a DataFrame with Pandas, you can add the inputs to the index argument. It will ensure that you get the index you want. If no inputs are specified, the DataFrame has a numerically valued index that starts at 0 and terminates on the DataFrame's last row.

Increasing the number of rows in a DataFrame: To insert rows in the DataFrame, we can use the.loc, iloc, and ix commands.

The loc is primarily used for our index's labels. It can be seen as if we insert in loc[4], which means we're seeking for DataFrame items with an index of 4.

The ix is a complex case because if the index is integer-based, we pass a label to ix. The ix[4] means that we are looking in the DataFrame for those values that have an index labeled 4. However, if the index is not only integer-based, ix will deal with the positions as iloc.

 

Ques. 13): How to Delete Indices, Rows or Columns From a Pandas Data Frame?

Answer:

Deleting an Index from Your DataFrame

If you want to remove the index from the DataFrame, you should have to do the following:

Reset the index of DataFrame.

Executing del df.index.name to remove the index name.

Remove duplicate index values by resetting the index and drop the duplicate values from the index column.

Remove an index with a row.

Deleting a Column from Your DataFrame

You can use the drop() method for deleting 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.

You can pass the argument inplace and set it to True to delete the column without reassign the DataFrame.

You can also delete the duplicate values from the column by using the drop_duplicates() method.

Removing a Row from Your DataFrame

By using df.drop_duplicates(), we can remove duplicate rows from the DataFrame.

You can use the drop() method to specify the index of the rows that we want to remove from the DataFrame.

 

Ques. 14): How to convert String to date?

Answer:

The below code demonstrates how to convert the string to date:

From datetime import datetime

# Define dates as the strings

dmy_str1 = ‘Wednesday, July 14, 2018’

dmy_str2 = ’14/7/17′

dmy_str3 = ’14-07-2017′

# Define dates as the datetime objects

dmy_dt1 = datetime.strptime(date_str1, ‘%A, %B %d, %Y’)

dmy_dt2 = datetime.strptime(date_str2, ‘%m/%d/%y’)

dmy_dt3 = datetime.strptime(date_str3, ‘%m-%d-%Y’)

#Print the converted dates

print(dmy_dt1)

print(dmy_dt2)

print(dmy_dt3)

 

Ques. 15): What exactly is the Pandas Index?

Answer:

Pandas indexing is as follows:

In pandas, indexing simply involves picking specific rows and columns of data from a DataFrame. Selecting all of the rows and some of the columns, part of the rows and all of the columns, or some of each of the rows and columns is what indexing entails. Subset selection is another name for indexing.

Using [],.loc[],.iloc[],.ix[] for Pandas indexing

A DataFrame's items, rows, and columns can be extracted in a variety of methods. In Pandas, there are some indexing methods that can be used to retrieve an element from a DataFrame. These indexing systems look to be fairly similar on the surface, however they perform extremely differently. Pandas supports four different methods of multi-axes indexing:

Dataframe.[ ] ; This function also known as indexing operator

Dataframe.loc[ ] : This function is used for labels.

Dataframe.iloc[ ] : This function is used for positions or integer based

Dataframe.ix[] : This function is used for both label and integer based

Collectively, they are called the indexers. These are by far the most common ways to index data. These are four function which help in getting the elements, rows, and columns from a DataFrame.

 

Ques. 16): Define ReIndexing?

Answer:

Reindexing changes the row labels and column labels of a DataFrame. To reindex means to conform the data to match a given set of labels along a particular axis.

Multiple operations can be accomplished through indexing like −

Reorder the existing data to match a new set of labels.

Insert missing value (NA) markers in label locations where no data for the label existed.

 

Ques. 17): How to Set the index?

Answer:

Python is an excellent language for data analysis, thanks to its vast ecosystem of data-centric Python packages. One of these packages is Pandas, which makes importing and analysing data a lot easier.

Pandas set index() is a function for setting the index of a Data Frame from a List, Series, or Data Frame. A data frame's index column can also be set while it's being created. However, because a data frame might be made up of two or more data frames, the index can be altered later using this method.

Syntax:

DataFrame.set_index(keys, drop=True, append=False, inplace=False, verify_integrity=False

 

Ques. 18): Define GroupBy in Pandas?

Answer:

Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.

Pandas dataframe.groupby() function is used to split the data into groups based on some criteria. pandas objects can be split on any of their axes. The abstract definition of grouping is to provide a mapping of labels to group names.

Syntax: DataFrame.groupby(by=None, axis=0, level=None, as_index=True, sort=True, group_keys=True, squeeze=False, **kwargs)

Parameters :

by : mapping, function, str, or iterable

axis : int, default 0

level : If the axis is a MultiIndex (hierarchical), group by a particular level or levels

as_index : For aggregated output, return object with group labels as the index. Only relevant for DataFrame input. as_index=False is effectively “SQL-style” grouped output

sort : Sort group keys. Get better performance by turning this off. Note this does not influence the order of observations within each group. groupby preserves the order of rows within each group.

group_keys : When calling apply, add group keys to index to identify pieces

squeeze : Reduce the dimensionality of the return type if possible, otherwise return a consistent type

Returns : GroupBy object

 

Ques. 19): How will you add a scalar column with same value for all rows to a pandas DataFrame?

Answer:

Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier.

Dataframe.add() method is used for addition of dataframe and other, element-wise (binary operator add). Equivalent to dataframe + other, but with support to substitute a fill_value for missing data in one of the inputs.

Syntax: DataFrame.add(other, axis=’columns’, level=None, fill_value=None)

Parameters:

other :Series, DataFrame, or constant

axis :{0, 1, ‘index’, ‘columns’} For Series input, axis to match Series index on

fill_value : [None or float value, default None] Fill missing (NaN) values with this value. If both DataFrame locations are missing, the result will be missing.

level : [int or name] Broadcast across a level, matching Index values on the passed MultiIndex level

Returns: result DataFrame

 

Ques. 20): In pandas, how can you see if a DataFrame is empty?

Answer:

Pandas DataFrame is a possibly heterogeneous two-dimensional size-mutable tabular data format with labelled axes (rows and columns). Both the row and column labels align for arithmetic operations. It can be viewed of as a container for Series items, similar to a dict. The Pandas' fundamental data structure is this.

Pandas DataFrame is a dataframe for Pandas.

The empty attribute determines whether or not the dataframe is empty. If the dataframe is empty, it returns True; otherwise, it returns False.

Syntax: DataFrame.empty

Parameter : None

Returns : bool