Extract series objects from Pandas DataFrame
<p>I have a dataframe with the columns</p>

<pre><code>['CPL4', 'Part Number', 'Calendar Year/Month', 'Sales', 'Inventory']
</code></pre>

<p>For each 'Part Number', 'Calendar Year/Month' will be unique on each Part Number.</p>

<p>I want to convert each part number to a univariate Series with 'Calendar Year/Month' as the index and either 'Sales' or 'Inventory' as the value.</p>

<p>How can I accomplish this using pandas built-in functions and not iterating through the dataframe manually?</p>

<p>From the answers and comments here, along with a little more research, I ended with the following solution.</p>

<pre><code>temp_series = df[df[ "Part Number" == sku ] ].pivot(columns = ["Calendar Year/Month"], values = "Sales").iloc[0]
</code></pre>

<p>Where sku is a specific part number from df["Part Number"].unique()</p>

<p>This will give you a univariate time series(temp_series) indexed by "Calendar Year/Month" with values of "Sales" EG:</p>

<pre><code>1.2015     NaN
1.2016     NaN
2.2015     NaN
2.2016     NaN
3.2015     NaN
3.2016     NaN
4.2015     NaN
4.2016     NaN
5.2015     NaN
5.2016     NaN
6.2015     NaN
6.2016     NaN
7.2015     NaN
7.2016     NaN
8.2015     NaN
8.2016     NaN
9.2015     NaN
10.2015    NaN
11.2015    NaN
12.2015    NaN
Name: 161, dtype: float64

&lt;class 'pandas.core.series.Series'&gt;])
</code></pre>

<p>from the columns</p>

<pre><code>['CPL4', 'Part Number', 'Calendar Year/Month', 'Sales', 'Inventory']
</code></pre>

python pandas dataframe time-series