Merge Dataframes in Pandas

This tutorial shows example how of merge dataframes in Pandas Python. In particular, merge() can be used to merge two dataframes. The basic syntax is as follows. merge(df_1,df_2, left_index=True, right_index=True) Below is the two dataframes to be merged. dataframe 1: car_location : Brand Location a Tesla CA b Toyota CA c Tesla NY d Ford … Read more

Pandas: Join Two Dataframes

We can use join() to combine dataframes in Python Pandas. The basic syntax is as follows, in which df_1 and df_2 represent two dataframes to be joined. df_1.join(df_2) The following includes examples showing how to join two dataframes using join(). Below is the two dataframes. dataframe 1: car_data: Brand Location a Tesla CA b Toyota CA … Read more

import pandas as pd

import pandas as pd serves two functions. First, import pandas tells Python to import the pandas library into the current programming environment. Second, as pd tells Python that you want to give a nickname pd for pandas. That is, pd will be alias for pandas. Example 1: Use import pandas as pd Brand Count 0 … Read more

Upload CSV to Github

This tutorial shows how can you upload CSV file to Github. It includes detailed steps and examples. Step 1: Create a new repository A new repository is where CSV files will be stored. Below. I created one and name it as machine_learning (Click here for the link.). Then, just hit the botton of Create repository. … Read more

Paired t-test in R (2 Examples)

Method 1 for paired t-test is for a situation group 1 and group 2 are two separate vectors, whereas Method 2 is for two groups of data in the same column. Method 1: t.test(group_1, group_2, paired = TRUE) Method 2: t.test(y~group, data=my_data, paired = TRUE) Data and Hypothesis Suppose we would like to test whether … Read more

Categories R

Pandas: Select Two Columns from a Dataframe (Examples)

There are at least 3 methods to select 2 or more than 2 columns from a dataframe in Python. Method 1: Use a list of column names df[ [ “col1”, “col2” ] ] Method 2: Use a range of column index df.iloc [ : , 0 : 2 ] Method 3: Use specific column indexes … Read more

Use sklearn for Linear Regression in Python

Introduction We can use sklearn.linear_model.LinearRegression to do linear regression in Python. The following is the core syntax of using sklearn. lm.fit(IVs, DV) Where, IVs: the independent variables DV: the dependent variable Example for Linear Regression Model The following is the linear regression model, including household income as IVs and purchase intention as DV. The following … Read more

Pandas: Read All Sheets in Excel

This tutorial shows how you can read multiple sheets in Excel in Python. The following shows the two major steps. Step 1: Read all sheets as a dictionary You can read all sheets in Excel altogether using the parameter of sheet_name=None in pd.read_excel(). Without this, it will only read the first sheet, by default. The … Read more

How to Convert Index as Column in Pandas

This tutorial shows how you can convert dataframe index as a column in Python. The basic syntax is to use reset_index() (see below). df_name.reset_index() Starting Dataframe for Examples 1 and 2 The following is the sample dataframe that will be used in Examples 1 and 2. (Note that, Example 3 will use a different dataframe.) … Read more

How to Clear or Empty a List in Python (Examples)

This tutorial shows 2 methods to clear a list in Python using examples. Method 1: Use clear() to empty a list You can use the method of clear() to empty a list in Python. The following is an example. [‘Tesla’, ‘Ford’, ‘Toyota’] [] Method 2: Use Del to clear or empty a list You can … Read more