Category: Python
How to Replace NaN with Zero in Pandas
You can replace NaN with zero using either fillna(0) in Pandas or replace(np.nan,0) in Numpy. Single Column: Method 1: df['Column_name'].fillna(0) Method 2: df['Column_name'].replace(np.nan,0) Whole dataframe: Method 1: df.fillna(0) Method 2: df.replace(np.nan,0) Example 1: single column The following Python code first...
Read Full Article →
Read CSV without the first column in Python
This tutorial includes two methods to read CSV without the first column in Python. Method 1: pd.read_csv(“CSV_file_name”,index_col=0) Method 2: df=pd.read_csv(“CSV_file_name”) del df[df.columns[0]] Example for Method 1 The following is an example showing without and with index_col=0 in read.csv(). The following...
Read Full Article →
Difference between Population Variance and Sample Variance
The difference between population variance and sample variance is on the denominator of the formula. In particular, the denominator for population variance is N, whereas sample variance is n-1. The following uses formulas and examples to explain the difference between...
Read Full Article →
Print Current Working Directory in Jupyter Notebook
This tutorial shows how you can print out the current working directory in Jupyter Notebook. In particular, you can use os.getcwd() to do it and this tutorial provides the complete Python code. In particular, the following is the Python code....
Read Full Article →
Convert CSV to Excel in Python
This tutorial shows how to convert CSV file to Excel in Python with examples and detailed steps. The following shows the specific steps. Steps of Convert CSV to Excel in Python Step 1 Install Pandas Pandas is a commonly used...
Read Full Article →
How to Convert List to String in Python (2 Examples)
This tutorial shows how to convert list to string in Python with examples. Example 1 The following Python code first generate a sample list and then use join() to change the list to string. The following is the output. ['a',...
Read Full Article →
The Difference between Naive versus Aware Datetime Objects in Python
Naive versus Aware Datetime Objects in Python The Difference between Naive versus Aware Datetime Objects is on time zone information: naive datetime objects does not have information on the time zone, whereas timezone-Aware datetime objects associate with timezone information Example...
Read Full Article →
How to Fix: has no attribute ‘dataframe’ in Python
This tutorial shows how to fix the error of has no attribute ‘dataframe’ in Python. The error could appear as follows. AttributeError: 'int' object has no attribute 'DataFrame' AttributeError: module 'pandas' has no attribute 'dataframe'. Did you mean: 'DataFrame'? AttributeError:...
Read Full Article →
Relationship between MSE and RSS
Formulas of MSE and RSS Residual Sum of Squares (RSS) is the numerator in the formula of Mean Squared Error (MSE). That is, RSS is part of MSE formula. where, \( n \) is the number of observations. \( \hat{y_i} \)...
Read Full Article →
Test Homogeneity of Variance in R
This tutorial shows methods test Homogeneity of Variance (or, Equality of Variance) in R. The methods include F-test, Bartlett’s test, Levene’s test, and Fligner-Killeen’s test. F-test: Compare variances of 2 groups. Need assumption of normality. Bartlett’s test: Compare variances of...
Read Full Article →