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?













0
















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?










share|improve this question
























  • Please provide df1 and df2 or their sample rows.

    – pistol2myhead
    Mar 7 at 10:20






  • 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






  • 2





    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






  • 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
















0
















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?










share|improve this question
























  • Please provide df1 and df2 or their sample rows.

    – pistol2myhead
    Mar 7 at 10:20






  • 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






  • 2





    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






  • 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














0












0








0









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?










share|improve this question

















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 at 12:34







Muppet

















asked Mar 7 at 10:16









MuppetMuppet

11




11












  • Please provide df1 and df2 or their sample rows.

    – pistol2myhead
    Mar 7 at 10:20






  • 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






  • 2





    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






  • 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


















  • Please provide df1 and df2 or their sample rows.

    – pistol2myhead
    Mar 7 at 10:20






  • 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






  • 2





    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






  • 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

















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













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
);



);













draft saved

draft discarded


















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















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

1928 у кіно

Захаров Федір Захарович

Ель Греко