ValueError: The truth value of a GeoDataFrame is ambiguous The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceCheck if string is in a pandas dataframeDataframe.isin() giving this error: The truth value of a DataFrame is ambiguousThe truth value of a Series is ambiguousDataFrame column comparison raises ValueError: The truth value of a Series is ambiguous.ValueError in pandas: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()why is my terminal outputting that my dataset has an ambiguous truth value and that i need to use a.all() or a.any()Python ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()pandas add columns ,note The truth value of a Series is ambiguousValueError (while creating a function in python): The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()Expanding Data frame with Loop. error problem
Simulating Exploding Dice
Did the UK government pay "millions and millions of dollars" to try to snag Julian Assange?
Take groceries in checked luggage
What information about me do stores get via my credit card?
ELI5: Why do they say that Israel would have been the fourth country to land a spacecraft on the Moon and why do they call it low cost?
Relations between two reciprocal partial derivatives?
Semisimplicity of the category of coherent sheaves?
How did passengers keep warm on sail ships?
Single author papers against my advisor's will?
Was credit for the black hole image misattributed?
Is it ethical to upload a automatically generated paper to a non peer-reviewed site as part of a larger research?
Is every episode of "Where are my Pants?" identical?
Wall plug outlet change
does high air pressure throw off wheel balance?
Derivation tree not rendering
Cooking pasta in a water boiler
Does Parliament hold absolute power in the UK?
Why did all the guest students take carriages to the Yule Ball?
How do you keep chess fun when your opponent constantly beats you?
What do you call a plan that's an alternative plan in case your initial plan fails?
Finding the path in a graph from A to B then back to A with a minimum of shared edges
The variadic template constructor of my class cannot modify my class members, why is that so?
Road tyres vs "Street" tyres for charity ride on MTB Tandem
Why can't devices on different VLANs, but on the same subnet, communicate?
ValueError: The truth value of a GeoDataFrame is ambiguous
The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experienceCheck if string is in a pandas dataframeDataframe.isin() giving this error: The truth value of a DataFrame is ambiguousThe truth value of a Series is ambiguousDataFrame column comparison raises ValueError: The truth value of a Series is ambiguous.ValueError in pandas: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()why is my terminal outputting that my dataset has an ambiguous truth value and that i need to use a.all() or a.any()Python ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()pandas add columns ,note The truth value of a Series is ambiguousValueError (while creating a function in python): The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()Expanding Data frame with Loop. error problem
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
Having issues filtering some 'name' values. I want to groupby month and name, after that filter a specific value from column name 'ar street3' and make a trend of that.
this is the code i wrote below:
df = pd.DataFrame(
'name' : ['ar street3', 'ar street 3', 'ba foo', 'br', ' oo', 'ke'],
'month' : [1, 2, 3, 4, 5, 6],
'score' : [2.0, 5., 8., 1., 2., 9.])
fig, ax = plt.subplots(figsize=(11,7))
df.groupby(['month', 'name']).filter(lambda x: 'ar street3' in x,df).mean(['score']).unstack().plot(ax.ax)
I get this type of error:
ValueError: The truth value of a GeoDataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Can somebody point me to the right direction ?
Thanks in advance.
python geopandas
|
show 1 more comment
Having issues filtering some 'name' values. I want to groupby month and name, after that filter a specific value from column name 'ar street3' and make a trend of that.
this is the code i wrote below:
df = pd.DataFrame(
'name' : ['ar street3', 'ar street 3', 'ba foo', 'br', ' oo', 'ke'],
'month' : [1, 2, 3, 4, 5, 6],
'score' : [2.0, 5., 8., 1., 2., 9.])
fig, ax = plt.subplots(figsize=(11,7))
df.groupby(['month', 'name']).filter(lambda x: 'ar street3' in x,df).mean(['score']).unstack().plot(ax.ax)
I get this type of error:
ValueError: The truth value of a GeoDataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Can somebody point me to the right direction ?
Thanks in advance.
python geopandas
What islambda x: 'ar' in x,merged2017
supposed to do? (a small reproducible example showing what kind of data you have + what you want to achieve would help)
– joris
Mar 8 at 13:54
Is the question clear now? lambda is supposed to filter out the values i specified above and make a trend of that.
– Reda S
Mar 8 at 14:03
The groupbyfilter
method expects a function (that is called on each group) and returns a boolean value. Butlambda x: 'ar' in x,merged2017
returns a tuple? Further, inlambda x: 'ar' in x
, x would be a DataFrame, so you are checking if 'ar' is a column of that subgroup DataFrame. Which is not what you want to do I suppose.
– joris
Mar 8 at 14:11
In general: maybe you want to filter before doing any grouping? (likedf[df['name'] == 'ar street3']
)
– joris
Mar 8 at 14:13
thank you, i didn't k now what the lambda did actually. I just filtered before grouping and it worked out.
– Reda S
Mar 8 at 14:26
|
show 1 more comment
Having issues filtering some 'name' values. I want to groupby month and name, after that filter a specific value from column name 'ar street3' and make a trend of that.
this is the code i wrote below:
df = pd.DataFrame(
'name' : ['ar street3', 'ar street 3', 'ba foo', 'br', ' oo', 'ke'],
'month' : [1, 2, 3, 4, 5, 6],
'score' : [2.0, 5., 8., 1., 2., 9.])
fig, ax = plt.subplots(figsize=(11,7))
df.groupby(['month', 'name']).filter(lambda x: 'ar street3' in x,df).mean(['score']).unstack().plot(ax.ax)
I get this type of error:
ValueError: The truth value of a GeoDataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Can somebody point me to the right direction ?
Thanks in advance.
python geopandas
Having issues filtering some 'name' values. I want to groupby month and name, after that filter a specific value from column name 'ar street3' and make a trend of that.
this is the code i wrote below:
df = pd.DataFrame(
'name' : ['ar street3', 'ar street 3', 'ba foo', 'br', ' oo', 'ke'],
'month' : [1, 2, 3, 4, 5, 6],
'score' : [2.0, 5., 8., 1., 2., 9.])
fig, ax = plt.subplots(figsize=(11,7))
df.groupby(['month', 'name']).filter(lambda x: 'ar street3' in x,df).mean(['score']).unstack().plot(ax.ax)
I get this type of error:
ValueError: The truth value of a GeoDataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Can somebody point me to the right direction ?
Thanks in advance.
python geopandas
python geopandas
edited Mar 8 at 14:07
Reda S
asked Mar 8 at 13:39
Reda SReda S
335
335
What islambda x: 'ar' in x,merged2017
supposed to do? (a small reproducible example showing what kind of data you have + what you want to achieve would help)
– joris
Mar 8 at 13:54
Is the question clear now? lambda is supposed to filter out the values i specified above and make a trend of that.
– Reda S
Mar 8 at 14:03
The groupbyfilter
method expects a function (that is called on each group) and returns a boolean value. Butlambda x: 'ar' in x,merged2017
returns a tuple? Further, inlambda x: 'ar' in x
, x would be a DataFrame, so you are checking if 'ar' is a column of that subgroup DataFrame. Which is not what you want to do I suppose.
– joris
Mar 8 at 14:11
In general: maybe you want to filter before doing any grouping? (likedf[df['name'] == 'ar street3']
)
– joris
Mar 8 at 14:13
thank you, i didn't k now what the lambda did actually. I just filtered before grouping and it worked out.
– Reda S
Mar 8 at 14:26
|
show 1 more comment
What islambda x: 'ar' in x,merged2017
supposed to do? (a small reproducible example showing what kind of data you have + what you want to achieve would help)
– joris
Mar 8 at 13:54
Is the question clear now? lambda is supposed to filter out the values i specified above and make a trend of that.
– Reda S
Mar 8 at 14:03
The groupbyfilter
method expects a function (that is called on each group) and returns a boolean value. Butlambda x: 'ar' in x,merged2017
returns a tuple? Further, inlambda x: 'ar' in x
, x would be a DataFrame, so you are checking if 'ar' is a column of that subgroup DataFrame. Which is not what you want to do I suppose.
– joris
Mar 8 at 14:11
In general: maybe you want to filter before doing any grouping? (likedf[df['name'] == 'ar street3']
)
– joris
Mar 8 at 14:13
thank you, i didn't k now what the lambda did actually. I just filtered before grouping and it worked out.
– Reda S
Mar 8 at 14:26
What is
lambda x: 'ar' in x,merged2017
supposed to do? (a small reproducible example showing what kind of data you have + what you want to achieve would help)– joris
Mar 8 at 13:54
What is
lambda x: 'ar' in x,merged2017
supposed to do? (a small reproducible example showing what kind of data you have + what you want to achieve would help)– joris
Mar 8 at 13:54
Is the question clear now? lambda is supposed to filter out the values i specified above and make a trend of that.
– Reda S
Mar 8 at 14:03
Is the question clear now? lambda is supposed to filter out the values i specified above and make a trend of that.
– Reda S
Mar 8 at 14:03
The groupby
filter
method expects a function (that is called on each group) and returns a boolean value. But lambda x: 'ar' in x,merged2017
returns a tuple? Further, in lambda x: 'ar' in x
, x would be a DataFrame, so you are checking if 'ar' is a column of that subgroup DataFrame. Which is not what you want to do I suppose.– joris
Mar 8 at 14:11
The groupby
filter
method expects a function (that is called on each group) and returns a boolean value. But lambda x: 'ar' in x,merged2017
returns a tuple? Further, in lambda x: 'ar' in x
, x would be a DataFrame, so you are checking if 'ar' is a column of that subgroup DataFrame. Which is not what you want to do I suppose.– joris
Mar 8 at 14:11
In general: maybe you want to filter before doing any grouping? (like
df[df['name'] == 'ar street3']
)– joris
Mar 8 at 14:13
In general: maybe you want to filter before doing any grouping? (like
df[df['name'] == 'ar street3']
)– joris
Mar 8 at 14:13
thank you, i didn't k now what the lambda did actually. I just filtered before grouping and it worked out.
– Reda S
Mar 8 at 14:26
thank you, i didn't k now what the lambda did actually. I just filtered before grouping and it worked out.
– Reda S
Mar 8 at 14:26
|
show 1 more comment
1 Answer
1
active
oldest
votes
If you want to combine filter and groupby in one line of code:
df = pd.DataFrame('name' : ['ar street3', 'ar street3', 'ba foo', 'br', ' oo', 'ke'],
'month' : [1, 2, 3, 4, 5, 6],
'score' : [2.0, 5., 8., 1., 2., 9.])
tag = 'ar street3'
df = df.groupby(['month', 'name']).filter(lambda x: tag in x.name)
print(df)
output:
name month score
0 ar street3 1 2.0
1 ar street3 2 5.0
if you want to add month condition:
tag = 'ar street3'; month = 1
df = df.groupby(['month', 'name']).filter(lambda x: tag in x.name and month == x.month)
name month score
0 ar street3 1 2.0
if you want only month:
#i have adapted the sample
df = pd.DataFrame('name' : ['ar street3', 'ar street3', 'ba foo', 'br', ' oo', 'ke'],
'month' : [1, 2, 3, 4, 5, 1],
'score' : [2.0, 5., 8., 1., 2., 9.])
month = 1
df = df.groupby(['month', 'name']).filter(lambda x: month == x.month)
output:
name month score
0 ar street3 1 2.0
5 ke 1 9.0
Thank you, is it possible to add an argument to the filter for selecting a specific month ?
– Reda S
Mar 9 at 11:59
i have modified my answer to do that
– Frenchy
Mar 10 at 5:32
thank you, this is very helpful
– Reda S
Mar 11 at 11:11
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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%2f55064416%2fvalueerror-the-truth-value-of-a-geodataframe-is-ambiguous%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you want to combine filter and groupby in one line of code:
df = pd.DataFrame('name' : ['ar street3', 'ar street3', 'ba foo', 'br', ' oo', 'ke'],
'month' : [1, 2, 3, 4, 5, 6],
'score' : [2.0, 5., 8., 1., 2., 9.])
tag = 'ar street3'
df = df.groupby(['month', 'name']).filter(lambda x: tag in x.name)
print(df)
output:
name month score
0 ar street3 1 2.0
1 ar street3 2 5.0
if you want to add month condition:
tag = 'ar street3'; month = 1
df = df.groupby(['month', 'name']).filter(lambda x: tag in x.name and month == x.month)
name month score
0 ar street3 1 2.0
if you want only month:
#i have adapted the sample
df = pd.DataFrame('name' : ['ar street3', 'ar street3', 'ba foo', 'br', ' oo', 'ke'],
'month' : [1, 2, 3, 4, 5, 1],
'score' : [2.0, 5., 8., 1., 2., 9.])
month = 1
df = df.groupby(['month', 'name']).filter(lambda x: month == x.month)
output:
name month score
0 ar street3 1 2.0
5 ke 1 9.0
Thank you, is it possible to add an argument to the filter for selecting a specific month ?
– Reda S
Mar 9 at 11:59
i have modified my answer to do that
– Frenchy
Mar 10 at 5:32
thank you, this is very helpful
– Reda S
Mar 11 at 11:11
add a comment |
If you want to combine filter and groupby in one line of code:
df = pd.DataFrame('name' : ['ar street3', 'ar street3', 'ba foo', 'br', ' oo', 'ke'],
'month' : [1, 2, 3, 4, 5, 6],
'score' : [2.0, 5., 8., 1., 2., 9.])
tag = 'ar street3'
df = df.groupby(['month', 'name']).filter(lambda x: tag in x.name)
print(df)
output:
name month score
0 ar street3 1 2.0
1 ar street3 2 5.0
if you want to add month condition:
tag = 'ar street3'; month = 1
df = df.groupby(['month', 'name']).filter(lambda x: tag in x.name and month == x.month)
name month score
0 ar street3 1 2.0
if you want only month:
#i have adapted the sample
df = pd.DataFrame('name' : ['ar street3', 'ar street3', 'ba foo', 'br', ' oo', 'ke'],
'month' : [1, 2, 3, 4, 5, 1],
'score' : [2.0, 5., 8., 1., 2., 9.])
month = 1
df = df.groupby(['month', 'name']).filter(lambda x: month == x.month)
output:
name month score
0 ar street3 1 2.0
5 ke 1 9.0
Thank you, is it possible to add an argument to the filter for selecting a specific month ?
– Reda S
Mar 9 at 11:59
i have modified my answer to do that
– Frenchy
Mar 10 at 5:32
thank you, this is very helpful
– Reda S
Mar 11 at 11:11
add a comment |
If you want to combine filter and groupby in one line of code:
df = pd.DataFrame('name' : ['ar street3', 'ar street3', 'ba foo', 'br', ' oo', 'ke'],
'month' : [1, 2, 3, 4, 5, 6],
'score' : [2.0, 5., 8., 1., 2., 9.])
tag = 'ar street3'
df = df.groupby(['month', 'name']).filter(lambda x: tag in x.name)
print(df)
output:
name month score
0 ar street3 1 2.0
1 ar street3 2 5.0
if you want to add month condition:
tag = 'ar street3'; month = 1
df = df.groupby(['month', 'name']).filter(lambda x: tag in x.name and month == x.month)
name month score
0 ar street3 1 2.0
if you want only month:
#i have adapted the sample
df = pd.DataFrame('name' : ['ar street3', 'ar street3', 'ba foo', 'br', ' oo', 'ke'],
'month' : [1, 2, 3, 4, 5, 1],
'score' : [2.0, 5., 8., 1., 2., 9.])
month = 1
df = df.groupby(['month', 'name']).filter(lambda x: month == x.month)
output:
name month score
0 ar street3 1 2.0
5 ke 1 9.0
If you want to combine filter and groupby in one line of code:
df = pd.DataFrame('name' : ['ar street3', 'ar street3', 'ba foo', 'br', ' oo', 'ke'],
'month' : [1, 2, 3, 4, 5, 6],
'score' : [2.0, 5., 8., 1., 2., 9.])
tag = 'ar street3'
df = df.groupby(['month', 'name']).filter(lambda x: tag in x.name)
print(df)
output:
name month score
0 ar street3 1 2.0
1 ar street3 2 5.0
if you want to add month condition:
tag = 'ar street3'; month = 1
df = df.groupby(['month', 'name']).filter(lambda x: tag in x.name and month == x.month)
name month score
0 ar street3 1 2.0
if you want only month:
#i have adapted the sample
df = pd.DataFrame('name' : ['ar street3', 'ar street3', 'ba foo', 'br', ' oo', 'ke'],
'month' : [1, 2, 3, 4, 5, 1],
'score' : [2.0, 5., 8., 1., 2., 9.])
month = 1
df = df.groupby(['month', 'name']).filter(lambda x: month == x.month)
output:
name month score
0 ar street3 1 2.0
5 ke 1 9.0
edited Mar 9 at 12:13
answered Mar 9 at 9:18
FrenchyFrenchy
2,4362518
2,4362518
Thank you, is it possible to add an argument to the filter for selecting a specific month ?
– Reda S
Mar 9 at 11:59
i have modified my answer to do that
– Frenchy
Mar 10 at 5:32
thank you, this is very helpful
– Reda S
Mar 11 at 11:11
add a comment |
Thank you, is it possible to add an argument to the filter for selecting a specific month ?
– Reda S
Mar 9 at 11:59
i have modified my answer to do that
– Frenchy
Mar 10 at 5:32
thank you, this is very helpful
– Reda S
Mar 11 at 11:11
Thank you, is it possible to add an argument to the filter for selecting a specific month ?
– Reda S
Mar 9 at 11:59
Thank you, is it possible to add an argument to the filter for selecting a specific month ?
– Reda S
Mar 9 at 11:59
i have modified my answer to do that
– Frenchy
Mar 10 at 5:32
i have modified my answer to do that
– Frenchy
Mar 10 at 5:32
thank you, this is very helpful
– Reda S
Mar 11 at 11:11
thank you, this is very helpful
– Reda S
Mar 11 at 11:11
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f55064416%2fvalueerror-the-truth-value-of-a-geodataframe-is-ambiguous%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
What is
lambda x: 'ar' in x,merged2017
supposed to do? (a small reproducible example showing what kind of data you have + what you want to achieve would help)– joris
Mar 8 at 13:54
Is the question clear now? lambda is supposed to filter out the values i specified above and make a trend of that.
– Reda S
Mar 8 at 14:03
The groupby
filter
method expects a function (that is called on each group) and returns a boolean value. Butlambda x: 'ar' in x,merged2017
returns a tuple? Further, inlambda x: 'ar' in x
, x would be a DataFrame, so you are checking if 'ar' is a column of that subgroup DataFrame. Which is not what you want to do I suppose.– joris
Mar 8 at 14:11
In general: maybe you want to filter before doing any grouping? (like
df[df['name'] == 'ar street3']
)– joris
Mar 8 at 14:13
thank you, i didn't k now what the lambda did actually. I just filtered before grouping and it worked out.
– Reda S
Mar 8 at 14:26