How to pass string variable with square brackets?What is the difference between String and string in C#?How do I iterate over the words of a string?How do I read / convert an InputStream into a String in Java?How do I pass a variable by reference?How do I make the first letter of a string uppercase in JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?Does Python have a string 'contains' substring method?How do I convert a String to an int in Java?Why is char[] preferred over String for passwords?
What do you call the infoboxes with text and sometimes images on the side of a page we find in textbooks?
Adding empty element to declared container without declaring type of element
Would it be legal for a US State to ban exports of a natural resource?
Can a controlled ghast be a leader of a pack of ghouls?
Identify a stage play about a VR experience in which participants are encouraged to simulate performing horrific activities
Perfect riffle shuffles
Organic chemistry Iodoform Reaction
Meta programming: Declare a new struct on the fly
The One-Electron Universe postulate is true - what simple change can I make to change the whole universe?
Is infinity mathematically observable?
Partial sums of primes
Can I use my Chinese passport to enter China after I acquired another citizenship?
Hostile work environment after whistle-blowing on coworker and our boss. What do I do?
Lifted its hind leg on or lifted its hind leg towards?
Is there an wasy way to program in Tikz something like the one in the image?
Why are all the doors on Ferenginar (the Ferengi home world) far shorter than the average Ferengi?
Why isn't KTEX's runway designation 10/28 instead of 9/27?
What was required to accept "troll"?
How do I repair my stair bannister?
What will be the benefits of Brexit?
What if somebody invests in my application?
Is it legal to discriminate due to the medicine used to treat a medical condition?
Did US corporations pay demonstrators in the German demonstrations against article 13?
Resetting two CD4017 counters simultaneously, only one resets
How to pass string variable with square brackets?
What is the difference between String and string in C#?How do I iterate over the words of a string?How do I read / convert an InputStream into a String in Java?How do I pass a variable by reference?How do I make the first letter of a string uppercase in JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?Does Python have a string 'contains' substring method?How do I convert a String to an int in Java?Why is char[] preferred over String for passwords?
df1
model horsepower
1 I30
2 CR-V
3 BMW 5 [F10] 13
df2
model horsepower
1 I30 15-17 100
2 CR-V 15- 130
3 BMW 5 [F10] 13-18 200
My goal is to find horsepower from df2 for each car model in df1:
for i,row in df1.iterrows():
var = row['model']
score = df2.loc[df2['model'].str.contains(var)]['horsepower'].item()
df1.at[i,'horsepower'] = score
I have a problem with this car model:
"BMW 5 [F10] 13-18"
Square brackets messes up the data and I get the error:
IndexError: single positional indexer is out-of-bounds
Everything works fine for all other models (tested on more over 100).
only BMW model messes thing up.
How can I solve this?
python string pandas
|
show 3 more comments
df1
model horsepower
1 I30
2 CR-V
3 BMW 5 [F10] 13
df2
model horsepower
1 I30 15-17 100
2 CR-V 15- 130
3 BMW 5 [F10] 13-18 200
My goal is to find horsepower from df2 for each car model in df1:
for i,row in df1.iterrows():
var = row['model']
score = df2.loc[df2['model'].str.contains(var)]['horsepower'].item()
df1.at[i,'horsepower'] = score
I have a problem with this car model:
"BMW 5 [F10] 13-18"
Square brackets messes up the data and I get the error:
IndexError: single positional indexer is out-of-bounds
Everything works fine for all other models (tested on more over 100).
only BMW model messes thing up.
How can I solve this?
python string pandas
Please providedf1
anddf2
or their sample rows.
– pistol2myhead
Mar 7 at 10:20
2
Perhapsdf1
anddf2
do not have the same index and size? You are using the index fromdf2
to look up indf1
.
– John Sloper
Mar 7 at 10:22
2
The square brackets are definitely not your problem.
– FChm
Mar 7 at 10:22
df1.at[i,horsepower] = score
wherehorsepower
should be'horsepower'
– Nihal
Mar 7 at 10:22
1
BMW 5[F10] 13
in df1 is not in df2->BMW 5 [F10] 13-18
, see the space between5
and[
– Frenchy
Mar 7 at 10:35
|
show 3 more comments
df1
model horsepower
1 I30
2 CR-V
3 BMW 5 [F10] 13
df2
model horsepower
1 I30 15-17 100
2 CR-V 15- 130
3 BMW 5 [F10] 13-18 200
My goal is to find horsepower from df2 for each car model in df1:
for i,row in df1.iterrows():
var = row['model']
score = df2.loc[df2['model'].str.contains(var)]['horsepower'].item()
df1.at[i,'horsepower'] = score
I have a problem with this car model:
"BMW 5 [F10] 13-18"
Square brackets messes up the data and I get the error:
IndexError: single positional indexer is out-of-bounds
Everything works fine for all other models (tested on more over 100).
only BMW model messes thing up.
How can I solve this?
python string pandas
df1
model horsepower
1 I30
2 CR-V
3 BMW 5 [F10] 13
df2
model horsepower
1 I30 15-17 100
2 CR-V 15- 130
3 BMW 5 [F10] 13-18 200
My goal is to find horsepower from df2 for each car model in df1:
for i,row in df1.iterrows():
var = row['model']
score = df2.loc[df2['model'].str.contains(var)]['horsepower'].item()
df1.at[i,'horsepower'] = score
I have a problem with this car model:
"BMW 5 [F10] 13-18"
Square brackets messes up the data and I get the error:
IndexError: single positional indexer is out-of-bounds
Everything works fine for all other models (tested on more over 100).
only BMW model messes thing up.
How can I solve this?
python string pandas
python string pandas
edited Mar 7 at 12:34
Muppet
asked Mar 7 at 10:16
MuppetMuppet
11
11
Please providedf1
anddf2
or their sample rows.
– pistol2myhead
Mar 7 at 10:20
2
Perhapsdf1
anddf2
do not have the same index and size? You are using the index fromdf2
to look up indf1
.
– John Sloper
Mar 7 at 10:22
2
The square brackets are definitely not your problem.
– FChm
Mar 7 at 10:22
df1.at[i,horsepower] = score
wherehorsepower
should be'horsepower'
– Nihal
Mar 7 at 10:22
1
BMW 5[F10] 13
in df1 is not in df2->BMW 5 [F10] 13-18
, see the space between5
and[
– Frenchy
Mar 7 at 10:35
|
show 3 more comments
Please providedf1
anddf2
or their sample rows.
– pistol2myhead
Mar 7 at 10:20
2
Perhapsdf1
anddf2
do not have the same index and size? You are using the index fromdf2
to look up indf1
.
– John Sloper
Mar 7 at 10:22
2
The square brackets are definitely not your problem.
– FChm
Mar 7 at 10:22
df1.at[i,horsepower] = score
wherehorsepower
should be'horsepower'
– Nihal
Mar 7 at 10:22
1
BMW 5[F10] 13
in df1 is not in df2->BMW 5 [F10] 13-18
, see the space between5
and[
– Frenchy
Mar 7 at 10:35
Please provide
df1
and df2
or their sample rows.– pistol2myhead
Mar 7 at 10:20
Please provide
df1
and df2
or their sample rows.– pistol2myhead
Mar 7 at 10:20
2
2
Perhaps
df1
and df2
do not have the same index and size? You are using the index from df2
to look up in df1
.– John Sloper
Mar 7 at 10:22
Perhaps
df1
and df2
do not have the same index and size? You are using the index from df2
to look up in df1
.– John Sloper
Mar 7 at 10:22
2
2
The square brackets are definitely not your problem.
– FChm
Mar 7 at 10:22
The square brackets are definitely not your problem.
– FChm
Mar 7 at 10:22
df1.at[i,horsepower] = score
where horsepower
should be 'horsepower'
– Nihal
Mar 7 at 10:22
df1.at[i,horsepower] = score
where horsepower
should be 'horsepower'
– Nihal
Mar 7 at 10:22
1
1
BMW 5[F10] 13
in df1 is not in df2->BMW 5 [F10] 13-18
, see the space between 5
and [
– Frenchy
Mar 7 at 10:35
BMW 5[F10] 13
in df1 is not in df2->BMW 5 [F10] 13-18
, see the space between 5
and [
– Frenchy
Mar 7 at 10:35
|
show 3 more comments
0
active
oldest
votes
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%2f55041268%2fhow-to-pass-string-variable-with-square-brackets%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f55041268%2fhow-to-pass-string-variable-with-square-brackets%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
Please provide
df1
anddf2
or their sample rows.– pistol2myhead
Mar 7 at 10:20
2
Perhaps
df1
anddf2
do not have the same index and size? You are using the index fromdf2
to look up indf1
.– John Sloper
Mar 7 at 10:22
2
The square brackets are definitely not your problem.
– FChm
Mar 7 at 10:22
df1.at[i,horsepower] = score
wherehorsepower
should be'horsepower'
– Nihal
Mar 7 at 10:22
1
BMW 5[F10] 13
in df1 is not in df2->BMW 5 [F10] 13-18
, see the space between5
and[
– Frenchy
Mar 7 at 10:35