Practical solutions

Python Pandas Howtos How-To Guides

Solve the problem. Keep building. Collection of Python Pandas how-to guide articles

Find the answer you need

Browse practical solutions, grouped by the task you're working on.

__COUNT__ entries on this page

How to Randomly Shuffle DataFrame Rows in PandasShuffle every row in a pandas DataFrame with pandas.DataFrame.sample(), numpy.random.permutation(), or sklearn.utils.shuffle(). How to Count Unique Values Per Group(s) in Pandascount values by grouping column in DataFrame using df.groupby().nunique(), df.groupby().agg(), and df.groupby().unique() methods in pandas library How to Read GZ File in PandasLoad a gzip-compressed CSV into a pandas DataFrame with read_csv, then inspect the rows. How to Vectorize a Function in PandasThis tutorial demonstrates how we can vectorize a function in pandas. How to Apply Function to Every Row in Pandas DataFrameLearn how to apply a callable to every row in a Pandas DataFrame with axis=1, including lambda, NumPy, and user-defined functions with or without extra arguments. How to Find Duplicate Rows in a DataFrame Using PandasLearn how to find duplicate rows in a Pandas DataFrame, compare all or selected columns, and control which occurrences are marked. How to Replace All the NaN Values With Zeros in a Column of a Pandas DataFrameLearn how to replace NaN values with zeros in a pandas DataFrame using the df.fillna() and df.replace() methods. This guide provides step-by-step instructions and code examples to help you clean your data effectively. Perfect for data analysis and machine learning tasks, this article will enhance your data manipulation skills while ensuring your datasets are ready for analysis. Three Ways to Normalize Numeric DataFrame Columns in PandasCompare mean (z-score) standardization, min-max scaling, and quantile normalization for numeric Pandas DataFrame columns, with formulas and reusable examples. How to Convert Pandas Series to DataFrameIt introduces how to convert pandas series to dataframe How to Convert Pandas DataFrame Column to ListThis article introduces how to convert Pandas DataFrame column to a list. How to Iterate Through Columns of a Pandas DataFrameThis tutorial demonstrates how to iterate through columns of a dataframe How to Export a Pandas Dataframe to an Excel FileThis tutorial represents various methods about how to export a pandas dataframe to an excel file How to Perform Stratified Sampling in PandasLearn how to draw equal-sized or population-proportional stratified samples from a Pandas DataFrame. How to Read Parquet File Into Pandas DataFrameThis tutorial demonstrates to read parquet files into a pandas dataframe in Python. How to Concatenate Two DataFrames in Pandas PythonWith the help of Pandas, it is possible to quickly combine series or dataframe with different types of set logic for the indexes and relational algebra capabilities for join and merge-type operations. How to Iterate Through Rows of a DataFrame in PandasCompare ways to read or process rows in a pandas DataFrame, including df.index, loc[], iloc[], iterrows(), itertuples(), and apply(). How to Create an Empty Column in Pandas DataFrameWe can add an empty column to DataFrame in Pandas using simple assignment operator, reindex(), assign() and insert() methods. How to Combine Two Columns of Text in DataFrame in Pandascombine columns in DataFrame using '+' operator, apply(), map(), str.cat(), agg() methods in pandas library How to Convert Pandas Dataframe to NumPy ArrayConvert a Pandas DataFrame to a NumPy array with to_numpy(), include its index, or create structured records with to_records(). How to Get the First Row of DataFrame PandasLearn to select the first row of a Pandas DataFrame with iloc, head(), filtering, query(), take(), and slicing, and choose a Series or DataFrame result. How to Drop Last Row and Column in PandasThis tutorial demonstrates how to delete rows and columns in a Pandas data frame in Python. How to Read SAS in PandasRead a SAS data file with Python or Pandas, inspect its rows, select columns with pyreadstat, and export the result to CSV. How to Extract Month and Year Separately From Datetime Column in PandasExtract numeric year and month values from a Pandas datetime column with the .dt accessor, or format them as strings with strftime(). How to Load Data From Text File in PandasLearn how to load delimited, fixed-width, and tab-separated text files into pandas DataFrames with the read_csv(), read_fwf(), and read_table() functions, including guidance on separators, headers, and missing values.