Turn a pandas Series into a NumPy Array
If you want to turn a pandas Series into a NumPy array, use Series.values.
Turn a pandas Series into a NumPy Array Read More »
If you want to turn a pandas Series into a NumPy array, use Series.values.
Turn a pandas Series into a NumPy Array Read More »
The apply method applies a function along an axis of a DataFrame. If you want to apply a function to a DataFrame elementwise, use applymap.
Apply a Function to a DataFrame Elementwise Read More »
Sometimes, when reading a CSV in pandas, you will get a Unnamed:0 column. To fix this, add index_col=0 to pandas.read_csv.
Fix Unnamed:0 When Reading a CSV in pandas Read More »
The cumulative maximum is the maximum of the numbers starting from 0 to the current index. If you want to get the cumulative maximum of a pandas DataFrame/Series, use cummax.Â
DataFrame.cumsum: Get Cumulative Sum Over Each Column Read More »
Imagine you are given a DataFrame with a date column. If you want to group your DataFrame by a specific frequency, use pd.Grouper. A Grouper allows you to customize your groupby instruction.
In the code above, I set freq=1W to group my data by weeks.Â
pandas Grouper: Group Values Based on a Specific Frequency Read More »
If you want to find rows that contain one of the substrings in a list, join that list using “|” then use the str.contains method.
Find Rows Containing One of the Substrings in a List Read More »
If you want to insert a column into a DataFrame at a specified location, use df.insert. In the code above, I insert column c at the location 0.Â
DataFrame.insert: Insert a Column Into a DataFrame at a Specified Location Read More »
DataFrame.all is useful when you want to evaluate whether all values of a row or a column are true. If you want to get the rows whose all values are NaN, use both isna and all.
all: Select Rows with All NaN Values Read More »
Applying a scikit-learn’s transformer on your DataFrame will return a NumPy array. If you want to return a pandas DataFrame instead, use SklearnTransformerWrapper along with your scikit-learn’s transformer.
This is a method of feature-engine.
Return a DataFrame When Using a scikit-learn’s Transformer Read More »
If you want to change the frequency of time-series data, use resample. In the code below, I use resample to show the records every two days instead of every day.
resample: Resample Time-Series Data Read More »