• Pandas DataFrame ‘value_count()’ Method.

    Pandas DataFrame ‘value_count()’ Method.

    Pandas DataFrame value_count() Method. Table Of Contents: Syntax ‘value_count( )’ Method In Pandas. Examples ‘value_count( )’ Method. (1) Syntax: DataFrame.value_counts(subset=None, normalize=False, sort=True, ascending=False, dropna=True Description: Return a Series containing counts of unique rows in the DataFrame. df[‘your_column’].value_counts() – this will return the count of unique occurences in the specified column. It is important to note that value_counts only works on pandas series, not Pandas dataframes. As a result, we only include one bracket df[‘your_column’] and not two brackets df[[‘your_column’]]. Parameters: subset: list-like, optional – Columns to use when counting unique combinations. normalize: bool, default False – Return proportions rather than frequencies. sort: bool,

    Read More

  • How To Count Distinct Values Of A Column In A DataFrame ??

    How To Count Distinct Values Of A Column In A DataFrame ??

    How To Count Distinct Values Of A Column? Table Of Contents: Syntax Of ‘nunique( )’ Method In Pandas. Examples ‘nunique( )’ Method. (1) Syntax: DataFrame.nunique(axis=0, dropna=True) Description: Count the number of distinct elements in the specified axis. Return Series with the number of distinct elements. Can ignore NaN values. Parameters: axis {0 or ‘index’, 1 or ‘columns’}, default 0 – The axis to use. 0 or ‘index’ for row-wise, 1 or ‘columns’ for column-wise. dropna: bool, default True – Don’t include NaN in the counts. Returns: Series (2) Examples Of nunique() Method: Example-1 import pandas as pd student = {‘Name’:[‘Subrat’,’Abhispa’,’Arpita’,’Anuradha’,’Namita’],

    Read More

  • Pandas DataFrame ‘eval’ Method.

    Pandas DataFrame ‘eval’ Method.

    Pandas DataFrame ‘eval’ Method. Table Of Contents: Syntax Of ‘eval( )’ Method In Pandas. Examples ‘eval( )’ Method. (1) Syntax: DataFrame.eval(expr, *, inplace=False, **kwargs) Description: Evaluate a string describing operations on DataFrame columns. Operates on columns only, not specific rows or elements. This allows eval to run arbitrary code, which can make you vulnerable to code injection if you pass user input to this function. Parameters: expr: str – The expression string to evaluate. in place: bool, default False – If the expression contains an assignment, whether to perform the operation in place and mutate the existing DataFrame. Otherwise, a new DataFrame

    Read More

  • How To Describe A DataFrame ?

    How To Describe A DataFrame ?

    How To Describe A DataFrame ? Table Of Contents: Syntax ‘describe()’ Method In Pandas. Examples ‘describe( )’ Method. (1) Syntax: DataFrame.describe(percentiles=None, include=None, exclude=None, datetime_is_numeric=False) Description: Generate descriptive statistics. Descriptive statistics include those that summarize the central tendency, dispersion and shape of a dataset’s distribution, excluding NaN values. Parameters: percentiles: list-like of numbers, optional- The percentiles to include in the output. All should fall between 0 and 1. The default is [.25, .5, .75], which returns the 25th, 50th, and 75th percentiles. include: ‘all’, list-like of dtypes or None (default), optional0 – A white list of data types to include in the result. Ignored for Series.

    Read More

  • Pandas DataFrame ‘count()’ Method.

    Pandas DataFrame ‘count()’ Method.

    Pandas DataFrame ‘count()’ Method Table Of Contents: Syntax Of ‘count( )’ Method In Pandas. Examples ‘count( )’ Method. (1) Syntax: DataFrame.count(axis=0, level=None, numeric_only=False) Description: Count non-NA cells for each column or row. The values None, NaN, NaT, and optionally numpy.inf (depending on pandas.options.mode.use_inf_as_na) are considered NA. Parameters: axis{0 or ‘index’, 1 or ‘columns’}, default 0 : If 0 or ‘index’ counts are generated for each column. If 1 or ‘columns’ counts are generated for each row. level: int or str, optional – If the axis is a MultiIndex (hierarchical), count along a particular level, collapsing into a DataFrame. A str specifies the level name. numeric_only: bool, default False – Include only float, int or boolean data Returns:

    Read More

  • Pandas DataFrame ‘groupby()’ Method.

    Pandas DataFrame ‘groupby()’ Method.

    Pandas DataFrame groupby() Method. Table Of Contents: Syntax ‘groupby( )’ Method In Pandas. Examples ‘groupby( )’ Method. (1) Syntax: DataFrame.groupby(by=None, axis=0, level=None, as_index=True, sort=True, group_keys=_NoDefault.no_default, squeeze=_NoDefault.no_default, observed=False, dropna=True) Description: Group related records together and apply some aggregate function. A groupby operation involves some combination of splitting the object, applying a function, and combining the results. This can be used to group large amounts of data and compute operations on these groups. Parameters: by: mapping, function, label, or list of labels- Used to determine the groups for the groupby. If by is a function, it’s called on each value of the object’s index. 

    Read More

  • Pandas DataFrame ‘applymap()’ Method.

    Pandas DataFrame ‘applymap()’ Method.

    Pandas DataFrame ‘applymap()’ Method. Table Of Contents: Syntax ‘applymap( )’ Method In Pandas. Examples ‘applymap( )’ Method. (1) Syntax: DataFrame.applymap(func, na_action=None, **kwargs) Description: Apply a function to a Dataframe elementwise. This method applies a function that accepts and returns a scalar to every element of a DataFrame. Parameters: func: callable – Python function, returns a single value from a single value. na_action: {None, ‘ignore’}, default None – If ‘ignore’, propagate NaN values, without passing them to func. **kwargs –  Additional keyword arguments to pass as keywords arguments to func. Returns: DataFrame : Transformed DataFrame. (2) Examples Of applymap() Method: Example-1 import pandas

    Read More

  • How To Apply Function To A DataFrame?

    How To Apply Function To A DataFrame?

    How To Apply Function To A DataFrame? Table Of Contents: Syntax ‘apply( )’ Method In Pandas. Examples ‘apply( )’ Method. (1) Syntax: DataFrame.apply(func, axis=0, raw=False, result_type=None, args=(), **kwargs) Description: Apply a function along an axis of the DataFrame. Parameters: func: function- Function to apply to each column or row. axis{0 or ‘index’, 1 or ‘columns’}, default 0 – Axis along which the function is applied: 0 or ‘index’: apply the function to each column. 1 or ‘columns’: apply the function to each row. rawbool, default False – Determines if row or column is passed as a Series or ndarray object:

    Read More

  • How To Apply Query To A DataFrame?

    How To Apply Query To A DataFrame?

    How To Apply Query To A DataFrame? Table Of Contents: Syntax ‘query( )’ Method In Pandas. Examples ‘query( )’ Method. (1) Syntax: DataFrame.query(expr, *, inplace=False, **kwargs) Description: Query the columns of a DataFrame with a boolean expression. Parameters: expr: str – The query string to evaluate. You can refer to variables in the environment by prefixing them with an ‘@’ character like @a + b. You can refer to column names that are not valid Python variable names by surrounding them in backticks.  Thus, column names containing spaces or punctuations (besides underscores) or starting with digits must be surrounded by backticks. (For example,

    Read More

  • Pandas DataFrame ‘mask()’ Method.

    Pandas DataFrame ‘mask()’ Method.

    Pandas DataFrame ‘mask( )’ Method. Table Of Contents: Syntax Of ‘mask( )’ Method In Pandas. Examples ‘mask( )’ Method. (1) Syntax: DataFrame.mask(cond, other=nan, *, inplace=False, axis=None, level=None, errors=’raise’, try_cast=_NoDefault.no_default) Description: Replace values where the condition is True. Where cond is False, keep the original value. Where True, replace with the corresponding value from other. Parameters: cond: bool Series/DataFrame, array-like, or callable – Where cond is False, keep the original value. Where True, replace with the corresponding value from other. other: scalar, Series/DataFrame, or callable – Entries where cond is True are replaced with the corresponding value from other. in place: bool, default False – Whether to

    Read More