Use of Melt, Pivot Table and String Operations in Python Pandas –
Pandas is a very important library for data analysis in Python. In today’s blog, we will discuss three major concepts – Melt Function, Pivot Table, and Vectorized String Operations. These three functions are very useful in data science, machine learning and algorithmic trading.
What is Pandas Melt Function?

melt() is used to convert data from wide format to long format. Suppose we have data of Apple, Amazon, Meta and Microsoft in different columns, then when we melt() this data, it will be converted into a long form, with the names of all the companies in one column and their respective values in the other.
When we create a plot on this melt() data, we see a basic chart. But if we present it as a bar chart (kind=’bar’), the visualization is better. There are dates on the X-axis and stock prices on the Y-axis. This makes our charts more clear and informative.
How to organize data with Pivot Table Function?
Pandas’ pivot_table() is a powerful tool that allows us to summarize data. When we are working with multi-level indexed data, we can easily extract any metrics such as “average price”, “maximum value” etc. using pivot_table().
It is often used for data analysis, financial reporting and market trend analysis. Especially when we analyze the stock prices of different companies over time.
Vectorized String Operations in Pandas
Python’s basic string operations are somewhat limited, but Pandas gives us advanced and vectorized string operations based on NumPy arrays. The advantage of this is that these operations are executed extremely fast and efficiently.
Using the .str accessor in Pandas, we can perform string manipulation such as:
.str.upper() – Convert all text to capital
.str.contains(“keyword”) – Search for a specific keyword
.str.replace() – Replace one text with another
In data analysis, we often have to compare text and numbers, especially when we are merging fundamental analysis and technical analysis. In such a situation, this information is very useful.
100 Days of Hell with Python Algo Trading – Day 31
This article is part of Day 31 of the “100 Days of Hell with Python Algo Trading” series. In the previous session, we learned in depth about multi-indexing, and in this blog, we have covered powerful topics like melt, pivot_table and string operations.
You are requested to also go through the previous topics, MCQs, task questions and mini projects so that your concepts become more clear.
Watch this Day 31 video tutorial
Day 31: Pivot Table and Melt in Pandas