Snippets Collections
# importing libraries 
from sklearn.ensemble import VotingClassifier ,BaggingClassifier, ExtraTreesClassifier, RandomForestClassifier
from sklearn.ensemble import AdaBoostClassifier,GradientBoostingClassifier
from sklearn.metrics import accuracy_score 
from numpy import mean,std
from sklearn.datasets import make_classification
from sklearn.model_selection import cross_val_score,RepeatedStratifiedKFold,train_test_split
from sklearn.linear_model import LogisticRegression,RidgeClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn.svm import SVC
from sklearn.naive_bayes import GaussianNB
from matplotlib import pyplot
from sklearn.datasets import load_wine,load_iris
from matplotlib.pyplot import figure
figure(num=2, figsize=(16, 12), dpi=80, facecolor='w', edgecolor='k')
import xgboost as xgb
from sklearn.feature_selection import SelectKBest,f_regression
from sklearn.linear_model import LinearRegression,BayesianRidge,ElasticNet,Lasso,SGDRegressor,Ridge
from sklearn.kernel_ridge import KernelRidge
from sklearn.preprocessing import LabelEncoder,OneHotEncoder,RobustScaler,StandardScaler
from sklearn.pipeline import make_pipeline,Pipeline
from sklearn.metrics import mean_squared_error
from sklearn.decomposition import PCA,KernelPCA
from sklearn.ensemble import ExtraTreesRegressor,GradientBoostingRegressor,RandomForestRegressor,VotingClassifier
from sklearn.model_selection import cross_val_score,KFold,GridSearchCV,RandomizedSearchCV,StratifiedKFold,train_test_split
from sklearn.base import BaseEstimator,clone,TransformerMixin,RegressorMixin
from sklearn.svm import LinearSVR,SVR
#import xgboost 
from xgboost import XGBRegressor
#Import Pandas
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
import seaborn as sns
import warnings
from scipy.stats import skew
from scipy.stats.stats import pearsonr
%matplotlib inline
seed = 1075
c3 = pd.Series(['China', 'US'])
# applying filter function 
df.filter(["Name", "College", "Salary"]) 

# importing pandas as pd 
import pandas as pd 
# Creating the dataframe  
df = pd.read_csv("nba.csv") 
# Using regular expression to extract all 
# columns which has letter 'a' or 'A' in its name. 
df.filter(regex ='[aA]') 
(df.groupby('name')['ext price']
 .agg(['mean', 'sum'])
df['column_name'] = pd.to_datetime(df['column_name'])
# new version
df.groupby(pd.Grouper(key='column_name', freq="M")).mean().plot()
def ffill_cols(df, cols_to_fill_name='Unn'):
    Forward fills column names. Propagate last valid column name forward to next invalid column. Works similarly to pandas
    :param df: pandas Dataframe; Dataframe
    :param cols_to_fill_name: str; The name of the columns you would like forward filled. Default is 'Unn' as
    the default name pandas gives unnamed columns is 'Unnamed'
    :returns: list; List of new column names
    cols = df.columns.to_list()
    for i, j in enumerate(cols):
        if j.startswith(cols_to_fill_name):
            cols[i] = cols[i-1]
    return cols

Sat Oct 31 2020 00:55:40 GMT+0000 (UTC)

#pandas #isin #filter

Sat Oct 31 2020 00:40:59 GMT+0000 (UTC)

#pandas #filter #column

Sat Oct 31 2020 00:38:58 GMT+0000 (UTC)

#pandas #filter

Mon Oct 26 2020 01:01:58 GMT+0000 (UTC)

#python #pandas #format #currency

Mon Oct 26 2020 00:28:49 GMT+0000 (UTC)

#python #pandas #formatting

Fri Oct 23 2020 04:54:30 GMT+0000 (UTC)

#pandas #duplicates #drop

Tue Oct 20 2020 09:28:55 GMT+0000 (UTC)

#python #pandas

Fri Oct 16 2020 22:26:07 GMT+0000 (UTC)

#python #pandas #grouper

Thu Aug 06 2020 08:57:00 GMT+0000 (UTC)

#python #pandas #data-cleaning

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension