Python Practice (Kaggle)

10 flashcards · Programming Languages · by charlie42

  1. Include non-numeric columns in df.describe()

    df.describe(include='all')

  2. Print types of all columns in a df

    df.dtypes

  3. Get first character from a column

    df[col].str[0]

  4. Convert column to a type

    df[col] = df[col].astype('str')

  5. Print a sorted array

    sorted(a)

  6. Check number of characeters in a column value

    df[col].str.len()

  7. Check if some character is in column value

    df[col].str.contains("a")

  8. Split by character and take first value

    df['first_part'] = df['col'].str.split(' ').str[0]

  9. Rename columns after groupby and aggregation

    grouped = df.grouby(col).count().reset_index() grouped.names = ["col", "col_count"] Need reset_index() because otherwise col will become the index

  10. Replace values across df

    df = df.replace(['nan', ''], np.nan)