Pivot table conversion generating value error in pands
up vote
0
down vote
favorite
I am fetching data from the table which contains
execution_time, type, status, process, sub_process, value
2018-11-12 16:09:48.179547, backlog, started, p1, s1, 100
2018-11-12 16:09:48.179547, backlog, created, p1, s1, 1005
2018-11-12 16:09:48.179547, backlog, started, p2, s1, 500
2018-11-12 16:09:48.179547, V1, created, p1, s1, 10
2018-11-12 16:09:48.179547, V2, created, p1, s1, 15
2018-11-12 16:09:48.179547, backlog, started, p3, s1, 0
2018-11-12 16:09:48.179547, backlog, started, p4, s1, 45
2018-11-12 16:09:48.179547, V1, started, p4, s1, 400
I want to pivot this data such that it should be like this:
status, process, sub_process, backlog, V1, V2
(backlog, V1 and V2 should contain corresponding values if exists)
Here is my code. I am getting error as
pivot_table() got multiple values for argument 'values'
sql = "select * from temp.data_table"
cursor.execute(sql)
results = cursor.fetchall()
df = pd.DataFrame(results)
df=df.pivot_table(index=['status','process','sub_process'],columns='type',values='value', aggfunc = 'sum')
python pandas cursor pivot
add a comment |
up vote
0
down vote
favorite
I am fetching data from the table which contains
execution_time, type, status, process, sub_process, value
2018-11-12 16:09:48.179547, backlog, started, p1, s1, 100
2018-11-12 16:09:48.179547, backlog, created, p1, s1, 1005
2018-11-12 16:09:48.179547, backlog, started, p2, s1, 500
2018-11-12 16:09:48.179547, V1, created, p1, s1, 10
2018-11-12 16:09:48.179547, V2, created, p1, s1, 15
2018-11-12 16:09:48.179547, backlog, started, p3, s1, 0
2018-11-12 16:09:48.179547, backlog, started, p4, s1, 45
2018-11-12 16:09:48.179547, V1, started, p4, s1, 400
I want to pivot this data such that it should be like this:
status, process, sub_process, backlog, V1, V2
(backlog, V1 and V2 should contain corresponding values if exists)
Here is my code. I am getting error as
pivot_table() got multiple values for argument 'values'
sql = "select * from temp.data_table"
cursor.execute(sql)
results = cursor.fetchall()
df = pd.DataFrame(results)
df=df.pivot_table(index=['status','process','sub_process'],columns='type',values='value', aggfunc = 'sum')
python pandas cursor pivot
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am fetching data from the table which contains
execution_time, type, status, process, sub_process, value
2018-11-12 16:09:48.179547, backlog, started, p1, s1, 100
2018-11-12 16:09:48.179547, backlog, created, p1, s1, 1005
2018-11-12 16:09:48.179547, backlog, started, p2, s1, 500
2018-11-12 16:09:48.179547, V1, created, p1, s1, 10
2018-11-12 16:09:48.179547, V2, created, p1, s1, 15
2018-11-12 16:09:48.179547, backlog, started, p3, s1, 0
2018-11-12 16:09:48.179547, backlog, started, p4, s1, 45
2018-11-12 16:09:48.179547, V1, started, p4, s1, 400
I want to pivot this data such that it should be like this:
status, process, sub_process, backlog, V1, V2
(backlog, V1 and V2 should contain corresponding values if exists)
Here is my code. I am getting error as
pivot_table() got multiple values for argument 'values'
sql = "select * from temp.data_table"
cursor.execute(sql)
results = cursor.fetchall()
df = pd.DataFrame(results)
df=df.pivot_table(index=['status','process','sub_process'],columns='type',values='value', aggfunc = 'sum')
python pandas cursor pivot
I am fetching data from the table which contains
execution_time, type, status, process, sub_process, value
2018-11-12 16:09:48.179547, backlog, started, p1, s1, 100
2018-11-12 16:09:48.179547, backlog, created, p1, s1, 1005
2018-11-12 16:09:48.179547, backlog, started, p2, s1, 500
2018-11-12 16:09:48.179547, V1, created, p1, s1, 10
2018-11-12 16:09:48.179547, V2, created, p1, s1, 15
2018-11-12 16:09:48.179547, backlog, started, p3, s1, 0
2018-11-12 16:09:48.179547, backlog, started, p4, s1, 45
2018-11-12 16:09:48.179547, V1, started, p4, s1, 400
I want to pivot this data such that it should be like this:
status, process, sub_process, backlog, V1, V2
(backlog, V1 and V2 should contain corresponding values if exists)
Here is my code. I am getting error as
pivot_table() got multiple values for argument 'values'
sql = "select * from temp.data_table"
cursor.execute(sql)
results = cursor.fetchall()
df = pd.DataFrame(results)
df=df.pivot_table(index=['status','process','sub_process'],columns='type',values='value', aggfunc = 'sum')
python pandas cursor pivot
python pandas cursor pivot
edited Nov 13 at 3:45
Aqueous Carlos
301113
301113
asked Nov 13 at 1:55
Madhura Mhatre
4119
4119
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Using (remove df
in pivot_table
)
df.pivot_table(index=['status','process','sub_process'],columns='type',values='value', aggfunc = 'sum')
Out[85]:
type V1 V2 backlog
status process sub_process
created p1 s1 10.0 15.0 1005.0
started p1 s1 NaN NaN 100.0
p2 s1 NaN NaN 500.0
p3 s1 NaN NaN 0.0
p4 s1 400.0 NaN 45.0
Or pd.pivot_table
pd.pivot_table(df,index=['status','process','sub_process'],columns='type',values=['value'], aggfunc = 'sum')
Out[86]:
value
type V1 V2 backlog
status process sub_process
created p1 s1 10.0 15.0 1005.0
started p1 s1 NaN NaN 100.0
p2 s1 NaN NaN 500.0
p3 s1 NaN NaN 0.0
p4 s1 400.0 NaN 45.0
hey @W-B I removed df but I am getting error as "KeyError: 'value'"
– Madhura Mhatre
Nov 13 at 3:21
@MadhuraMhatre check you df columns by df.columns , i think you have white space there
– W-B
Nov 13 at 3:22
This is what my revised line looks like df=df.pivot_table(index=['status','process','sub_process'],columns='type',values='value',aggfunc ='sum')
– Madhura Mhatre
Nov 13 at 3:28
@MadhuraMhatre runing fine on my side .
– W-B
Nov 13 at 3:31
Thats interesting I still get that "KeyError: 'value'"
– Madhura Mhatre
Nov 13 at 3:46
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Using (remove df
in pivot_table
)
df.pivot_table(index=['status','process','sub_process'],columns='type',values='value', aggfunc = 'sum')
Out[85]:
type V1 V2 backlog
status process sub_process
created p1 s1 10.0 15.0 1005.0
started p1 s1 NaN NaN 100.0
p2 s1 NaN NaN 500.0
p3 s1 NaN NaN 0.0
p4 s1 400.0 NaN 45.0
Or pd.pivot_table
pd.pivot_table(df,index=['status','process','sub_process'],columns='type',values=['value'], aggfunc = 'sum')
Out[86]:
value
type V1 V2 backlog
status process sub_process
created p1 s1 10.0 15.0 1005.0
started p1 s1 NaN NaN 100.0
p2 s1 NaN NaN 500.0
p3 s1 NaN NaN 0.0
p4 s1 400.0 NaN 45.0
hey @W-B I removed df but I am getting error as "KeyError: 'value'"
– Madhura Mhatre
Nov 13 at 3:21
@MadhuraMhatre check you df columns by df.columns , i think you have white space there
– W-B
Nov 13 at 3:22
This is what my revised line looks like df=df.pivot_table(index=['status','process','sub_process'],columns='type',values='value',aggfunc ='sum')
– Madhura Mhatre
Nov 13 at 3:28
@MadhuraMhatre runing fine on my side .
– W-B
Nov 13 at 3:31
Thats interesting I still get that "KeyError: 'value'"
– Madhura Mhatre
Nov 13 at 3:46
add a comment |
up vote
0
down vote
Using (remove df
in pivot_table
)
df.pivot_table(index=['status','process','sub_process'],columns='type',values='value', aggfunc = 'sum')
Out[85]:
type V1 V2 backlog
status process sub_process
created p1 s1 10.0 15.0 1005.0
started p1 s1 NaN NaN 100.0
p2 s1 NaN NaN 500.0
p3 s1 NaN NaN 0.0
p4 s1 400.0 NaN 45.0
Or pd.pivot_table
pd.pivot_table(df,index=['status','process','sub_process'],columns='type',values=['value'], aggfunc = 'sum')
Out[86]:
value
type V1 V2 backlog
status process sub_process
created p1 s1 10.0 15.0 1005.0
started p1 s1 NaN NaN 100.0
p2 s1 NaN NaN 500.0
p3 s1 NaN NaN 0.0
p4 s1 400.0 NaN 45.0
hey @W-B I removed df but I am getting error as "KeyError: 'value'"
– Madhura Mhatre
Nov 13 at 3:21
@MadhuraMhatre check you df columns by df.columns , i think you have white space there
– W-B
Nov 13 at 3:22
This is what my revised line looks like df=df.pivot_table(index=['status','process','sub_process'],columns='type',values='value',aggfunc ='sum')
– Madhura Mhatre
Nov 13 at 3:28
@MadhuraMhatre runing fine on my side .
– W-B
Nov 13 at 3:31
Thats interesting I still get that "KeyError: 'value'"
– Madhura Mhatre
Nov 13 at 3:46
add a comment |
up vote
0
down vote
up vote
0
down vote
Using (remove df
in pivot_table
)
df.pivot_table(index=['status','process','sub_process'],columns='type',values='value', aggfunc = 'sum')
Out[85]:
type V1 V2 backlog
status process sub_process
created p1 s1 10.0 15.0 1005.0
started p1 s1 NaN NaN 100.0
p2 s1 NaN NaN 500.0
p3 s1 NaN NaN 0.0
p4 s1 400.0 NaN 45.0
Or pd.pivot_table
pd.pivot_table(df,index=['status','process','sub_process'],columns='type',values=['value'], aggfunc = 'sum')
Out[86]:
value
type V1 V2 backlog
status process sub_process
created p1 s1 10.0 15.0 1005.0
started p1 s1 NaN NaN 100.0
p2 s1 NaN NaN 500.0
p3 s1 NaN NaN 0.0
p4 s1 400.0 NaN 45.0
Using (remove df
in pivot_table
)
df.pivot_table(index=['status','process','sub_process'],columns='type',values='value', aggfunc = 'sum')
Out[85]:
type V1 V2 backlog
status process sub_process
created p1 s1 10.0 15.0 1005.0
started p1 s1 NaN NaN 100.0
p2 s1 NaN NaN 500.0
p3 s1 NaN NaN 0.0
p4 s1 400.0 NaN 45.0
Or pd.pivot_table
pd.pivot_table(df,index=['status','process','sub_process'],columns='type',values=['value'], aggfunc = 'sum')
Out[86]:
value
type V1 V2 backlog
status process sub_process
created p1 s1 10.0 15.0 1005.0
started p1 s1 NaN NaN 100.0
p2 s1 NaN NaN 500.0
p3 s1 NaN NaN 0.0
p4 s1 400.0 NaN 45.0
answered Nov 13 at 2:21
W-B
93.3k72755
93.3k72755
hey @W-B I removed df but I am getting error as "KeyError: 'value'"
– Madhura Mhatre
Nov 13 at 3:21
@MadhuraMhatre check you df columns by df.columns , i think you have white space there
– W-B
Nov 13 at 3:22
This is what my revised line looks like df=df.pivot_table(index=['status','process','sub_process'],columns='type',values='value',aggfunc ='sum')
– Madhura Mhatre
Nov 13 at 3:28
@MadhuraMhatre runing fine on my side .
– W-B
Nov 13 at 3:31
Thats interesting I still get that "KeyError: 'value'"
– Madhura Mhatre
Nov 13 at 3:46
add a comment |
hey @W-B I removed df but I am getting error as "KeyError: 'value'"
– Madhura Mhatre
Nov 13 at 3:21
@MadhuraMhatre check you df columns by df.columns , i think you have white space there
– W-B
Nov 13 at 3:22
This is what my revised line looks like df=df.pivot_table(index=['status','process','sub_process'],columns='type',values='value',aggfunc ='sum')
– Madhura Mhatre
Nov 13 at 3:28
@MadhuraMhatre runing fine on my side .
– W-B
Nov 13 at 3:31
Thats interesting I still get that "KeyError: 'value'"
– Madhura Mhatre
Nov 13 at 3:46
hey @W-B I removed df but I am getting error as "KeyError: 'value'"
– Madhura Mhatre
Nov 13 at 3:21
hey @W-B I removed df but I am getting error as "KeyError: 'value'"
– Madhura Mhatre
Nov 13 at 3:21
@MadhuraMhatre check you df columns by df.columns , i think you have white space there
– W-B
Nov 13 at 3:22
@MadhuraMhatre check you df columns by df.columns , i think you have white space there
– W-B
Nov 13 at 3:22
This is what my revised line looks like df=df.pivot_table(index=['status','process','sub_process'],columns='type',values='value',aggfunc ='sum')
– Madhura Mhatre
Nov 13 at 3:28
This is what my revised line looks like df=df.pivot_table(index=['status','process','sub_process'],columns='type',values='value',aggfunc ='sum')
– Madhura Mhatre
Nov 13 at 3:28
@MadhuraMhatre runing fine on my side .
– W-B
Nov 13 at 3:31
@MadhuraMhatre runing fine on my side .
– W-B
Nov 13 at 3:31
Thats interesting I still get that "KeyError: 'value'"
– Madhura Mhatre
Nov 13 at 3:46
Thats interesting I still get that "KeyError: 'value'"
– Madhura Mhatre
Nov 13 at 3:46
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53272669%2fpivot-table-conversion-generating-value-error-in-pands%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown