Skip to content

Instantly share code, notes, and snippets.

@Tech-49
Last active January 20, 2023 10:10
Show Gist options
  • Select an option

  • Save Tech-49/5bb4449d8eff6a1e2076aed695afa09b to your computer and use it in GitHub Desktop.

Select an option

Save Tech-49/5bb4449d8eff6a1e2076aed695afa09b to your computer and use it in GitHub Desktop.

Revisions

  1. Tech-49 revised this gist Jan 20, 2023. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion Python_helper.txt
    Original file line number Diff line number Diff line change
    @@ -36,4 +36,8 @@ df.loc[:, ['col_1', 'col_2']]
    X[X['cluster_2'].isin([0])].reset_index()

    # Sum of rows
    df = df.sum(axis = 1)
    df = df.sum(axis = 1)

    # Create dataframe from dictionary (Key as columns)
    a={'b':100,'c':300}
    pd.DataFrame(coefs, index=[0,])
  2. Tech-49 revised this gist Dec 12, 2022. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion Python_helper.txt
    Original file line number Diff line number Diff line change
    @@ -33,4 +33,7 @@ df.iloc[[index]]
    df.loc[:, ['col_1', 'col_2']]

    # Filter rows in dataframe where cluster_2 is 0
    X[X['cluster_2'].isin([0])].reset_index()
    X[X['cluster_2'].isin([0])].reset_index()

    # Sum of rows
    df = df.sum(axis = 1)
  3. Tech-49 revised this gist Nov 14, 2022. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion Python_helper.txt
    Original file line number Diff line number Diff line change
    @@ -30,4 +30,7 @@ df.copy(deep=True)
    df.iloc[[index]]

    # Fetch multiple columns.
    df.loc[:, ['col_1', 'col_2']]
    df.loc[:, ['col_1', 'col_2']]

    # Filter rows in dataframe where cluster_2 is 0
    X[X['cluster_2'].isin([0])].reset_index()
  4. Tech-49 revised this gist Nov 14, 2022. 2 changed files with 33 additions and 8 deletions.
    33 changes: 33 additions & 0 deletions Python_helper.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    -------------------
    Pandas
    -------------------

    # Create dataframe from dictionary
    df = pd.DataFrame.from_dict(data["trainData"])

    # Convert entire dataframe values to numeric type.
    df = df.apply(pd.to_numeric, errors='ignore')

    # Remove missing value.
    df = df.dropna()

    # Create a new column named "new_col" with value "2" if cluster_id column has value 1, else 0.
    df.insert(loc=0, column=new_col, value=np.where(cluster_id == 1, 2, 0))

    # Create a new column named "new_col" with value of df["log2_livable"] if cluster_id is 1, else 0.
    df.insert(loc=0, column=new_col, value=np.where(cluster_id == 1, df["log2_livable"], 0))

    # Change date format of entire column.
    effective_date = pd.to_datetime(df["effective_date"], format='%Y-%m-%d')

    # Re-order dataframe by columns (A-Z)
    df = df[sorted(df.columns)]

    # Clone dataframe
    df.copy(deep=True)

    # Fetch the row based on given index.
    df.iloc[[index]]

    # Fetch multiple columns.
    df.loc[:, ['col_1', 'col_2']]
    8 changes: 0 additions & 8 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,8 +0,0 @@
    # Create dataframe from dictionary
    df = pd.DataFrame.from_dict(data["trainData"])

    # Convert to numeric type.
    df = df.apply(pd.to_numeric, errors='ignore')

    # Remove missing value.
    df = df.dropna()
  5. Tech-49 created this gist Nov 14, 2022.
    8 changes: 8 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    # Create dataframe from dictionary
    df = pd.DataFrame.from_dict(data["trainData"])

    # Convert to numeric type.
    df = df.apply(pd.to_numeric, errors='ignore')

    # Remove missing value.
    df = df.dropna()