Things I learn from the personal work.
1. Modules
1.1 random.random()
Randomly generates a real number (a number with a decimal point) greater than or equal to 0 and less than or equal to 1.
1.2 random.randint(a, b)
Returns a random integer between a and b.
1.3 random.uniform(a, b)
Returns a random real number between a and b.
1.4 random.choice(seq)
Randomly selects a value from the given **sequence(seq)**.
The sequence can be a list, tuple, string, etc.
1.5 random.sample(seq, k)
Randomly selects k random values from the given **sequence(seq)**.
1.6 random.shuffle(seq)
Randomly shuffles the order of a list.
Replacing the missing data
1. fillna() method
This method replaces NaN values with other values.
DataFrame['column_name'].fillna(replace_value, inplace=False)
replace_value: The value you want to insert instead of NaN (e.g. 'No 0')
inplace: Whether to modify the original data (default is False)
2. replace() method
DataFrame['column_name'].replace({replace_value: new_value}, inplace=False)
replace_value: The value you want to replace (e.g. pd.NA or np.nan)
new_value: The new value you want to insert (e.g. 'No 0')
3. where() method
This method leaves the values that satisfy the condition as they are and replaces the values that do not satisfy the condition with other values. DataFrame['column_name'].where(condition, value_to_replace)
Condition: Conditional expression (e.g. DataFrame['column_name'].notna())
Replacement_value: The value you want to put in the value that does not satisfy the condition (e.g. 'no_word')
4. mask() method
This method changes the values that satisfy the condition to other values and leaves the values that do not satisfy the condition as they are.
DataFrame['column_name'].mask(condition, value_to_replace)
Condition: Conditional expression (e.g. DataFrame['column_name'].isna())
Replacement_value: The value you want to put in the values that satisfy the condition (e.g. 'no_word')
5. apply() method
This method allows you to apply a function to each element of a data frame. DataFrame['column name'].apply(function)
Function: Function to apply to each value (e.g. lambda x: 'no sphere' if pd.isna(x) else x)
6. numpy.where() function
This is a method to select two values based on a condition. You must use numpy.
np.where(condition, value_when_true, value_when_false)
Condition: Conditional expression (e.g. DataFrame['column name'].isna())
Value_when_true: The value you want to insert when the condition is true (e.g. 'no sphere')
Value_when_false: The value to keep when the condition is false (e.g. DataFrame['column name'])
7.rename
DataFrame.rename(columns={old name: new name}, index={old index: new index}, inplace=False)
8. List comprehension
[<value> for <element> in <list> if <condition>]
The map function calls a function, or applies a mapping, to each element of a given Series.
Good night