Linked Questions
1,136 questions linked to/from How can I pivot a dataframe?
114
votes
2
answers
227k
views
Python Pandas: Convert Rows as Column headers [duplicate]
I have the following dataframe:
Year Country medal no of medals
1896 Afghanistan Gold 5
1896 Afghanistan Silver 4
1896 Afghanistan Bronze 3
...
103
votes
2
answers
100k
views
Pandas column values to columns? [duplicate]
I've seen a few variations on the theme of exploding a column/series into multiple columns of a Pandas dataframe, but I've been trying to do something and not really succeeding with the existing ...
31
votes
2
answers
66k
views
When pivoting a Pandas dataframe, how do I make the column names the same as in R? (flat, label in column names)
I have a dataframe (df) that looks like this:
+---------+-------+------------+----------+
| subject | pills | date | strength |
+---------+-------+------------+----------+
| 1 | 4 | 10/...
31
votes
4
answers
50k
views
Pandas - transpose one column [duplicate]
I'm having difficulty using transpose with pandas.
I have the following df:
date name quantity
1/1/2018 A 5
1/1/2018 B 6
1/1/2018 C 7
1/2/2018 A 9
...
10
votes
2
answers
50k
views
Pandas Convert Some Rows to Columns in Python [duplicate]
So my dataset has some information by business n dates as below:
Business Date Value
a 1/1/2017 127
a 2/1/2017 89
b 2/1/2017 122
a 1/1/2018 555
a ...
15
votes
1
answer
22k
views
Pandas: How to pivot one column in rows into columns [duplicate]
Given this dataframe:
feature score searchTerm
0 a 0.534509 pizza
1 b 0.586020 pizza
2 c 0.588972 pizza
3 a 0.566261 chinese
4 b 0.572405 chinese
5 c 0....
5
votes
1
answer
12k
views
create pivot table in pandas using count of occurrence of value [duplicate]
I'm attempting to create cross-table / pivot table in pandas:
import pandas as pd
import numpy as np
df = pd.DataFrame({'foo': ['one', 'one', 'one', 'two', 'two','two'],'bar': ['A', 'A', 'C', 'B', '...
5
votes
2
answers
5k
views
Pandas - How to make new columns from unique values and group by unique value? [duplicate]
I have such dataframe:
import pandas as pd
data = [
[1, 'A', 10], [1, 'B', 20], [1, 'C', 30],
[2, 'A', 30], [2, 'B', 20], [2, 'C', 10],
[3, 'A', 20], [3, 'B', 40], [3, 'C', 20]...
5
votes
1
answer
21k
views
Reshaping Long Data to Wide in Python (Pandas) [duplicate]
I'm trying to reshape my long data to a wide format. The data currently looks like:
OBS . date . TICKER . RET
1 . 20050131 . AAPL . 0.02
2 . 20050231 . AAPL . 0.01
3 . 20050131 . GOOG . 0.05
4 . ...
6
votes
3
answers
9k
views
pandas pivoting a dataframe, duplicate rows [duplicate]
I'm having a little trouble with pivoting in pandas. The dataframe (dates, location, data) I'm working on looks like:
dates location data
date1 A X
date2 A Y
date3 ...
6
votes
2
answers
6k
views
How to pivot one column containing strings in a dataframe? [duplicate]
I am trying to reshape a pandas dataframe, by turning one of the columns in the data, into rows (by pivoting or unstacking).
I am new to this, so likely that I'm missing something obvious. I've ...
5
votes
4
answers
2k
views
Get counts by group using pandas [duplicate]
I have a pandas dataframe which contains data as shown below:
ID year_month_id Class
1 201612 A
2 201612 D
3 201612 B
4 201612 Other
5 201612 ...
5
votes
3
answers
3k
views
How do I count number of occurrences per minute in a pandas data frame [duplicate]
I have a pandas data frame like this:
timestamp status
2019-01-01 09:00:00 FAILED
2019-01-01 09:00:00 FAILED
2019-01-01 09:00:00 UNKNOWN
2019-01-01 09:00:00 PASSED
2019-01-01 09:00:00 ...
5
votes
2
answers
3k
views
Python Pandas - Groupby and make column values headers [duplicate]
I have a dataframe which is a list of organisations (multiple rows per organisation) which has a boolean value associated with it.
So organisation A has 3 true rows and 3 false i.e.
Organisation ...
1
vote
2
answers
7k
views
Pandas dataframe convert row to column [duplicate]
I am fetching data from a source into a pandas data frame, it is like below
date
currency
price
d1
INR
31
d2
INR
32
d2
USD
21
d3
USD
41
d3
INR
51
d3
JPY
61
I want to convert it to below
date
INR
JPY
...