data frame replace contents of a rowReplacements for switch statement in Python?How to replace a character by a newline in VimHow to replace all occurrences of a string in JavaScriptHow to join (merge) data frames (inner, outer, left, right)R - list to data frameDrop data frame columns by nameR: losing column names when adding rows to an empty data frameCreate an empty data.frameHow to iterate over rows in a DataFrame in Pandas?Select rows from a DataFrame based on values in a column in pandas

Did Darth Vader wear the same suit for 20+ years?

Why did Hela need Heimdal's sword?

Completing the square to find if quadratic form is positive definite.

How to supress loops in a digraph?

What happens to foam insulation board after you pour concrete slab?

What can plausibly explain many of my very long and low-tech bridges?

Why does the Schrödinger equation work so well for the Hydrogen atom despite the relativistic boundary at the nucleus?

How were concentration and extermination camp guards recruited?

What is in `tex.print` or `tex.sprint`?

Does the expansion of the universe increase with distance?

How could a government be implemented in a virtual reality?

Do manufacturers try make their components as close to ideal ones as possible?

C SIGINT signal in Linux

How do photons get into the eyes?

Does the growth of home value benefit from compound interest?

Bent spoke design wheels — feasible?

Sharing one invocation list between multiple events on the same object in C#

What risks are there when you clear your cookies instead of logging off?

Is it possible for people to live in the eye of a permanent hypercane?

Will TSA allow me to carry a Continuous Positive Airway Pressure (CPAP)/sleep apnea device?

When writing an error prompt, should we end the sentence with a exclamation mark or a dot?

How to generate random points without duplication?

Avoiding cliches when writing gods

You've spoiled/damaged the card



data frame replace contents of a row


Replacements for switch statement in Python?How to replace a character by a newline in VimHow to replace all occurrences of a string in JavaScriptHow to join (merge) data frames (inner, outer, left, right)R - list to data frameDrop data frame columns by nameR: losing column names when adding rows to an empty data frameCreate an empty data.frameHow to iterate over rows in a DataFrame in Pandas?Select rows from a DataFrame based on values in a column in pandas






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I've created a data frame named dataframe_tweets. It contain a heading 'text' with the text of the tweet. The tweets where searched and saved into this data frame. All search terms are saved in a list called artist_name_no_duplicate. I want to create a new column called Artist_Mentioned which is the contains the name of the artist contained within artist_name_no_duplicate which is mentioned in that row in the text column. I've tried .contains, .replace, changing it into an array but to no avail.



Change the list into an array so we can search and replace using replace function:



import numpy as np**:

myarray = np.asarray(artist_name_no_duplicate)

i = 30
artist_name = myarray[i]
print(artist_name)


Create new column:



dataframe_tweets['Artist_Mentioned'] = dataframe_tweets['text']


Filter new column so it just contains the artist name which is mentioned:



dataframe_tweets.loc[dataframe_tweets['Artist_Mentioned'].str.contains('myarray[i]'), 'Artist_Mentioned'] = myarray[i]


Print data frame:



dataframe_tweets


Currently it's working but only searching for the actual text 'myarray[i]' but I want it to search the string contained in the i'th position of the array called myarray.Any help is greatly appreciated!










share|improve this question
























  • This is a python 3.0 question

    – Robert Blake
    Mar 24 at 16:19

















0















I've created a data frame named dataframe_tweets. It contain a heading 'text' with the text of the tweet. The tweets where searched and saved into this data frame. All search terms are saved in a list called artist_name_no_duplicate. I want to create a new column called Artist_Mentioned which is the contains the name of the artist contained within artist_name_no_duplicate which is mentioned in that row in the text column. I've tried .contains, .replace, changing it into an array but to no avail.



Change the list into an array so we can search and replace using replace function:



import numpy as np**:

myarray = np.asarray(artist_name_no_duplicate)

i = 30
artist_name = myarray[i]
print(artist_name)


Create new column:



dataframe_tweets['Artist_Mentioned'] = dataframe_tweets['text']


Filter new column so it just contains the artist name which is mentioned:



dataframe_tweets.loc[dataframe_tweets['Artist_Mentioned'].str.contains('myarray[i]'), 'Artist_Mentioned'] = myarray[i]


Print data frame:



dataframe_tweets


Currently it's working but only searching for the actual text 'myarray[i]' but I want it to search the string contained in the i'th position of the array called myarray.Any help is greatly appreciated!










share|improve this question
























  • This is a python 3.0 question

    – Robert Blake
    Mar 24 at 16:19













0












0








0


1






I've created a data frame named dataframe_tweets. It contain a heading 'text' with the text of the tweet. The tweets where searched and saved into this data frame. All search terms are saved in a list called artist_name_no_duplicate. I want to create a new column called Artist_Mentioned which is the contains the name of the artist contained within artist_name_no_duplicate which is mentioned in that row in the text column. I've tried .contains, .replace, changing it into an array but to no avail.



Change the list into an array so we can search and replace using replace function:



import numpy as np**:

myarray = np.asarray(artist_name_no_duplicate)

i = 30
artist_name = myarray[i]
print(artist_name)


Create new column:



dataframe_tweets['Artist_Mentioned'] = dataframe_tweets['text']


Filter new column so it just contains the artist name which is mentioned:



dataframe_tweets.loc[dataframe_tweets['Artist_Mentioned'].str.contains('myarray[i]'), 'Artist_Mentioned'] = myarray[i]


Print data frame:



dataframe_tweets


Currently it's working but only searching for the actual text 'myarray[i]' but I want it to search the string contained in the i'th position of the array called myarray.Any help is greatly appreciated!










share|improve this question
















I've created a data frame named dataframe_tweets. It contain a heading 'text' with the text of the tweet. The tweets where searched and saved into this data frame. All search terms are saved in a list called artist_name_no_duplicate. I want to create a new column called Artist_Mentioned which is the contains the name of the artist contained within artist_name_no_duplicate which is mentioned in that row in the text column. I've tried .contains, .replace, changing it into an array but to no avail.



Change the list into an array so we can search and replace using replace function:



import numpy as np**:

myarray = np.asarray(artist_name_no_duplicate)

i = 30
artist_name = myarray[i]
print(artist_name)


Create new column:



dataframe_tweets['Artist_Mentioned'] = dataframe_tweets['text']


Filter new column so it just contains the artist name which is mentioned:



dataframe_tweets.loc[dataframe_tweets['Artist_Mentioned'].str.contains('myarray[i]'), 'Artist_Mentioned'] = myarray[i]


Print data frame:



dataframe_tweets


Currently it's working but only searching for the actual text 'myarray[i]' but I want it to search the string contained in the i'th position of the array called myarray.Any help is greatly appreciated!







python dataframe replace






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 24 at 15:19









amanb

2,6412826




2,6412826










asked Mar 24 at 14:41









Robert BlakeRobert Blake

11




11












  • This is a python 3.0 question

    – Robert Blake
    Mar 24 at 16:19

















  • This is a python 3.0 question

    – Robert Blake
    Mar 24 at 16:19
















This is a python 3.0 question

– Robert Blake
Mar 24 at 16:19





This is a python 3.0 question

– Robert Blake
Mar 24 at 16:19












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%2f55324933%2fdata-frame-replace-contents-of-a-row%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%2f55324933%2fdata-frame-replace-contents-of-a-row%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

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript