Merge and Create Cartesian Product from DataFrames in Python Pandas

AmitDiwan
Updated on 29-Sep-2021 07:21:01

2K+ Views

To merge Pandas DataFrame, use the merge() function. The cartesian product is implemented on both the DataFrames by setting under the “how” parameter of the merge() function i.e. −how = “cross”At first, let us import the pandas library with an alias −import pandas as pd Create DataFrame1 −dataFrame1 = pd.DataFrame(    {       "Car": ['BMW', 'Mustang', 'Bentley', 'Jaguar'], "Units": [100, 150, 110, 120] } )Create DataFrame2dataFrame2 = pd.DataFrame(    {       "Car": ['BMW', 'Tesla', 'Jaguar'], "Reg_Price": [7000, 8000, 9000] } )Next, merge DataFrames with "cross" in "how" parameter i.e. ... Read More

Merge Pandas DataFrame with Common Column and Set NaN for Unmatched Values

AmitDiwan
Updated on 29-Sep-2021 07:09:45

894 Views

To merge two Pandas DataFrame with common column, use the merge() function and set the ON parameter as the column name. To set NaN for unmatched values, use the “how” parameter and set it left or right. That would mean, merging left or right.At first, let us import the pandas library with an alias −import pandas as pdLet us create DataFrame1 −dataFrame1 = pd.DataFrame(    {       "Car": ['BMW', 'Lexus', 'Audi', 'Mustang', 'Bentley', 'Jaguar'], "Units": [100, 150, 110, 80, 110, 90] } )Let us create DataFrame2dataFrame2 = pd.DataFrame(    {       "Car": ['BMW', ... Read More

Create MultiIndex from DataFrame in Python Pandas

AmitDiwan
Updated on 29-Sep-2021 06:50:34

724 Views

To create Multiindex from DataFrame, use the MultiIndex. from_frame() method. At first, let us create a Dictionary of lists −d = {'Car': ['BMW', 'Lexus', 'Audi', 'Mercedes', 'Jaguar', 'Bentley'], 'Date_of_purchase': ['2020-10-10', '2020-10-12', '2020-10-17', '2020-10-16', '2020-10-19', '2020-10-22'] }Next, create a Pandas DataFrame from the above dictionary of lists −dataFrame = pd.DataFrame(d)Now create multiindex using from_frame() −print(pd.MultiIndex.from_frame(dataFrame))ExampleFollowing is the code −import pandas as pd # dictionary of lists d = {'Car': ['BMW', 'Lexus', 'Audi', 'Mercedes', 'Jaguar', 'Bentley'], 'Date_of_purchase': ['2020-10-10', '2020-10-12', '2020-10-17', '2020-10-16', '2020-10-19', '2020-10-22']} # creating dataframe from the above dictionary of lists dataFrame = pd.DataFrame(d) print("DataFrame...", dataFrame) # creating ... Read More

Difference Between Security Market Line (SML) and Capital Market Line (CML)

Probir Banerjee
Updated on 29-Sep-2021 06:14:04

9K+ Views

The security market line (SML) is a graph that is drawn with the values obtained from the capital asset pricing model (CAPM). It is a theoretical presentation of expected returns of assets that are based on systematic risk.Non-diversifiable risk is not represented by the SML. In a broader sense, the SML shows the expected market returns at a given level of market risk for marketable security. The overall level of risk is measured by the beta of the security against the market level of risk.Security Market Line AssumptionsSince the security market line is a representation of the CAPM, the assumptions ... Read More

Relationship Between Correlation and Covariance

Probir Banerjee
Updated on 29-Sep-2021 06:11:45

1K+ Views

In simple words, both correlation and covariance show the relationship and the dependency between two variables.Covariance shows the direction of the path of the linear relationship between the variables while a function is applied to them.Correlation on the contrary measures both the power and direction of the linear relationship between two variables.In simple terms, correlation is a function of the covariance. The fact that differentiates the two is that covariance values are not standardized while correlation values are. The correlation coefficient of two variables can be obtained by dividing the covariance values of these variables by the multiplication of the ... Read More

What is Minimum Variance Portfolio

Probir Banerjee
Updated on 29-Sep-2021 06:09:34

2K+ Views

In a study done to link the variance with returns, it was found that both genres of portfolio construction measures – minimum volatility and low volatility – deliver market return more than the average. Their information ratios (IRs) also are not statistically significant. It was also found that both strategies let investors assume palpable risk, in relation to the market prices, for which investors were not compensated.Minimum Variance Portfolio (MVP)The concept of Modern Portfolio Theory (MPT) has been the milestone for finance professionals for portfolio construction since Harry Markowitz introduced the idea into finance in 1952. Every finance student has ... Read More

What is Meant by Capital Market Line

Probir Banerjee
Updated on 29-Sep-2021 06:08:09

1K+ Views

Capital Market Line (CML) is a line that talks about a portfolio that accurately combines both risk and returns. It is a graphical representation that shows a portfolio’s expected and required return based on a chosen level of risk. The portfolios that are on the CML optimize the required risk and return relationship that maximizes the performance of the portfolio.Note − The slope of Capital Market Line is known as the Sharpe Ratio of the market portfolio. It is now believed by many investors that one should buy a security if the Sharpe ratio is above the CML and sell ... Read More

Mean-Variance Criterion for Defining Efficient and Inefficient Assets

Probir Banerjee
Updated on 29-Sep-2021 06:05:47

850 Views

Mean-Variance AnalysisMean-Variance Analysis is a process that investors utilize to make investment decisions based on their risk tolerance. Investors actually consider the potential variance given by the volatility of returns produced by an asset in the market against the required expected returns of that asset. The mean-variance analysis looks into the average variance in the required expected return from an investment.The mean-variance analysis is a part of Modern Portfolio Theory (MPT) which is based on the assumption that investors tend to make rational decisions when they possess enough information. The theory also relies on the fact that investors enter the ... Read More

What is Capital Asset Pricing Model (CAPM)

Probir Banerjee
Updated on 29-Sep-2021 06:02:25

944 Views

What is CAPM?The Capital Asset Pricing Model (CAPM) describes the association between the anticipated return and the risks of investing in a security. It represents the fact that the expected return on an asset is equal to the risk-free return rate plus a premium for taking the risk that is based on the beta of the security.Assessing the CAPM requires proper knowledge of systematic and unsystematic risks.Systematic risks are the general dangers, which apply to all forms of investment. For example, inflation rate, Wars, recessions, etc., are systematic risks.Unsystematic risks, on the other hand, show the specific dangers associated with ... Read More

Building an Animated Loader in React JS

Ath Tripathi
Updated on 28-Sep-2021 13:02:08

947 Views

In this article, we will see how to make an animated loader in React.js. Animated loaders are used in many websites to enhance the look and feel. In React.js, we can use the react-spinkit package to create beautiful animated loaders easily without having to write hundreds of lines of CSS.First create a React project −npx create-react-app tutorialpurposeGo to the project directory −cd tutorialpurposeExampleInstall the react-spinkit package −npm i --save react-spinkitThis library provides premade loaders and it is really easy to add it in your project. Using spinner, you can add any animated loader in React.Add the following lines of code ... Read More

Advertisements