AttributeError: 'str' object has no attribute 'copy' from user input Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!User input and command line argumentsHow to sort a list of objects based on an attribute of the objects?How to know if an object has an attribute in PythonAttributeError: 'module' object has no attributeAttributeError(“'str' object has no attribute 'read'”)Asking the user for input until they give a valid responsepython pandas: call pandas function on objects inherited from DataFrameRetain function and creation a of new table in python panda as SASPandas setting a value on a copy of a slice error when updating columnsPython - AttributeError: 'DataFrame' object has no attribute

Central Vacuuming: Is it worth it, and how does it compare to normal vacuuming?

Delete free apps from library

What does Turing mean by this statement?

Why is it faster to reheat something than it is to cook it?

Can two person see the same photon?

How do living politicians protect their readily obtainable signatures from misuse?

Positioning dot before text in math mode

Did Mueller's report provide an evidentiary basis for the claim of Russian govt election interference via social media?

Found this skink in my tomato plant bucket. Is he trapped? Or could he leave if he wanted?

Trying to understand entropy as a novice in thermodynamics

How can a team of shapeshifters communicate?

How would a mousetrap for use in space work?

Is CEO the "profession" with the most psychopaths?

Google .dev domain strangely redirects to https

Resize vertical bars (absolute-value symbols)

What adaptations would allow standard fantasy dwarves to survive in the desert?

How does light 'choose' between wave and particle behaviour?

How does the math work when buying airline miles?

How would you say "es muy psicólogo"?

Should a wizard buy fine inks every time he want to copy spells into his spellbook?

What does 丫 mean? 丫是什么意思?

Would color changing eyes affect vision?

Where is the Next Backup Size entry on iOS 12?

Putting class ranking in CV, but against dept guidelines



AttributeError: 'str' object has no attribute 'copy' from user input



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!User input and command line argumentsHow to sort a list of objects based on an attribute of the objects?How to know if an object has an attribute in PythonAttributeError: 'module' object has no attributeAttributeError(“'str' object has no attribute 'read'”)Asking the user for input until they give a valid responsepython pandas: call pandas function on objects inherited from DataFrameRetain function and creation a of new table in python panda as SASPandas setting a value on a copy of a slice error when updating columnsPython - AttributeError: 'DataFrame' object has no attribute



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








0















I've this dataframe:



dtf = pd.DataFrame('col1' : ['Buenos Dias'],
'col2' : ["Hello"],
'col3' : ["Bonjour"])


I need to accept user input dataframe name using this fonction and make a copy.
I get an error message "'str' object has no attribute 'copy' "
So, how translate this "str" into pandas ?



def copydf():
global dfNewName
dfname = input(" Enter dataframe Name :")
print (dfname)
dfNewName = dfname.copy()


Thank you if you can help.










share|improve this question






















  • why do you need a "copy" why not just use the string you got from the input?

    – JacobIRR
    Mar 8 at 22:25











  • What exactly are you trying to accomplish? Where should the user input go? You're receiving an error because you are trying to use the copy method on a string (user input is always a string like "hello world"). Maybe you are expecting dfname to be a pandas dataframe?

    – lvrf
    Mar 8 at 22:28












  • Yes the Idea is to create a copy "dfNewName" from the dataframe "dtf"

    – Carlos Carvalho
    Mar 8 at 23:05











  • @JacobIRR - That's the issue, what returns from the input it's just a string, is not recognized by pandas.

    – Carlos Carvalho
    Mar 8 at 23:17

















0















I've this dataframe:



dtf = pd.DataFrame('col1' : ['Buenos Dias'],
'col2' : ["Hello"],
'col3' : ["Bonjour"])


I need to accept user input dataframe name using this fonction and make a copy.
I get an error message "'str' object has no attribute 'copy' "
So, how translate this "str" into pandas ?



def copydf():
global dfNewName
dfname = input(" Enter dataframe Name :")
print (dfname)
dfNewName = dfname.copy()


Thank you if you can help.










share|improve this question






















  • why do you need a "copy" why not just use the string you got from the input?

    – JacobIRR
    Mar 8 at 22:25











  • What exactly are you trying to accomplish? Where should the user input go? You're receiving an error because you are trying to use the copy method on a string (user input is always a string like "hello world"). Maybe you are expecting dfname to be a pandas dataframe?

    – lvrf
    Mar 8 at 22:28












  • Yes the Idea is to create a copy "dfNewName" from the dataframe "dtf"

    – Carlos Carvalho
    Mar 8 at 23:05











  • @JacobIRR - That's the issue, what returns from the input it's just a string, is not recognized by pandas.

    – Carlos Carvalho
    Mar 8 at 23:17













0












0








0








I've this dataframe:



dtf = pd.DataFrame('col1' : ['Buenos Dias'],
'col2' : ["Hello"],
'col3' : ["Bonjour"])


I need to accept user input dataframe name using this fonction and make a copy.
I get an error message "'str' object has no attribute 'copy' "
So, how translate this "str" into pandas ?



def copydf():
global dfNewName
dfname = input(" Enter dataframe Name :")
print (dfname)
dfNewName = dfname.copy()


Thank you if you can help.










share|improve this question














I've this dataframe:



dtf = pd.DataFrame('col1' : ['Buenos Dias'],
'col2' : ["Hello"],
'col3' : ["Bonjour"])


I need to accept user input dataframe name using this fonction and make a copy.
I get an error message "'str' object has no attribute 'copy' "
So, how translate this "str" into pandas ?



def copydf():
global dfNewName
dfname = input(" Enter dataframe Name :")
print (dfname)
dfNewName = dfname.copy()


Thank you if you can help.







python pandas dataframe






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 8 at 22:21









Carlos CarvalhoCarlos Carvalho

103




103












  • why do you need a "copy" why not just use the string you got from the input?

    – JacobIRR
    Mar 8 at 22:25











  • What exactly are you trying to accomplish? Where should the user input go? You're receiving an error because you are trying to use the copy method on a string (user input is always a string like "hello world"). Maybe you are expecting dfname to be a pandas dataframe?

    – lvrf
    Mar 8 at 22:28












  • Yes the Idea is to create a copy "dfNewName" from the dataframe "dtf"

    – Carlos Carvalho
    Mar 8 at 23:05











  • @JacobIRR - That's the issue, what returns from the input it's just a string, is not recognized by pandas.

    – Carlos Carvalho
    Mar 8 at 23:17

















  • why do you need a "copy" why not just use the string you got from the input?

    – JacobIRR
    Mar 8 at 22:25











  • What exactly are you trying to accomplish? Where should the user input go? You're receiving an error because you are trying to use the copy method on a string (user input is always a string like "hello world"). Maybe you are expecting dfname to be a pandas dataframe?

    – lvrf
    Mar 8 at 22:28












  • Yes the Idea is to create a copy "dfNewName" from the dataframe "dtf"

    – Carlos Carvalho
    Mar 8 at 23:05











  • @JacobIRR - That's the issue, what returns from the input it's just a string, is not recognized by pandas.

    – Carlos Carvalho
    Mar 8 at 23:17
















why do you need a "copy" why not just use the string you got from the input?

– JacobIRR
Mar 8 at 22:25





why do you need a "copy" why not just use the string you got from the input?

– JacobIRR
Mar 8 at 22:25













What exactly are you trying to accomplish? Where should the user input go? You're receiving an error because you are trying to use the copy method on a string (user input is always a string like "hello world"). Maybe you are expecting dfname to be a pandas dataframe?

– lvrf
Mar 8 at 22:28






What exactly are you trying to accomplish? Where should the user input go? You're receiving an error because you are trying to use the copy method on a string (user input is always a string like "hello world"). Maybe you are expecting dfname to be a pandas dataframe?

– lvrf
Mar 8 at 22:28














Yes the Idea is to create a copy "dfNewName" from the dataframe "dtf"

– Carlos Carvalho
Mar 8 at 23:05





Yes the Idea is to create a copy "dfNewName" from the dataframe "dtf"

– Carlos Carvalho
Mar 8 at 23:05













@JacobIRR - That's the issue, what returns from the input it's just a string, is not recognized by pandas.

– Carlos Carvalho
Mar 8 at 23:17





@JacobIRR - That's the issue, what returns from the input it's just a string, is not recognized by pandas.

– Carlos Carvalho
Mar 8 at 23:17












1 Answer
1






active

oldest

votes


















0














You need to pass the user input with eval function.



import pandas as pd

dtf = pd.DataFrame('col1' : ['Buenos Dias'],
'col2' : ["Hello"],
'col3' : ["Bonjour"])

def copydf():
dfname = input(" Enter dataframe Name :")
try:
newdf = eval(dfname).copy()
return newdf
except NameError:
print("Dataframe not found")


new_df= copydf() #this is your copied dataframe





share|improve this answer

























  • It looked good but I get another error message : ValueError: If using all scalar values, you must pass an index

    – Carlos Carvalho
    Mar 8 at 23:12












  • That's simply perfect. You're great.Thank you

    – Carlos Carvalho
    Mar 9 at 0:16












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%2f55071808%2fattributeerror-str-object-has-no-attribute-copy-from-user-input%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









0














You need to pass the user input with eval function.



import pandas as pd

dtf = pd.DataFrame('col1' : ['Buenos Dias'],
'col2' : ["Hello"],
'col3' : ["Bonjour"])

def copydf():
dfname = input(" Enter dataframe Name :")
try:
newdf = eval(dfname).copy()
return newdf
except NameError:
print("Dataframe not found")


new_df= copydf() #this is your copied dataframe





share|improve this answer

























  • It looked good but I get another error message : ValueError: If using all scalar values, you must pass an index

    – Carlos Carvalho
    Mar 8 at 23:12












  • That's simply perfect. You're great.Thank you

    – Carlos Carvalho
    Mar 9 at 0:16
















0














You need to pass the user input with eval function.



import pandas as pd

dtf = pd.DataFrame('col1' : ['Buenos Dias'],
'col2' : ["Hello"],
'col3' : ["Bonjour"])

def copydf():
dfname = input(" Enter dataframe Name :")
try:
newdf = eval(dfname).copy()
return newdf
except NameError:
print("Dataframe not found")


new_df= copydf() #this is your copied dataframe





share|improve this answer

























  • It looked good but I get another error message : ValueError: If using all scalar values, you must pass an index

    – Carlos Carvalho
    Mar 8 at 23:12












  • That's simply perfect. You're great.Thank you

    – Carlos Carvalho
    Mar 9 at 0:16














0












0








0







You need to pass the user input with eval function.



import pandas as pd

dtf = pd.DataFrame('col1' : ['Buenos Dias'],
'col2' : ["Hello"],
'col3' : ["Bonjour"])

def copydf():
dfname = input(" Enter dataframe Name :")
try:
newdf = eval(dfname).copy()
return newdf
except NameError:
print("Dataframe not found")


new_df= copydf() #this is your copied dataframe





share|improve this answer















You need to pass the user input with eval function.



import pandas as pd

dtf = pd.DataFrame('col1' : ['Buenos Dias'],
'col2' : ["Hello"],
'col3' : ["Bonjour"])

def copydf():
dfname = input(" Enter dataframe Name :")
try:
newdf = eval(dfname).copy()
return newdf
except NameError:
print("Dataframe not found")


new_df= copydf() #this is your copied dataframe






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 9 at 20:27

























answered Mar 8 at 22:47









hawk1337hawk1337

207




207












  • It looked good but I get another error message : ValueError: If using all scalar values, you must pass an index

    – Carlos Carvalho
    Mar 8 at 23:12












  • That's simply perfect. You're great.Thank you

    – Carlos Carvalho
    Mar 9 at 0:16


















  • It looked good but I get another error message : ValueError: If using all scalar values, you must pass an index

    – Carlos Carvalho
    Mar 8 at 23:12












  • That's simply perfect. You're great.Thank you

    – Carlos Carvalho
    Mar 9 at 0:16

















It looked good but I get another error message : ValueError: If using all scalar values, you must pass an index

– Carlos Carvalho
Mar 8 at 23:12






It looked good but I get another error message : ValueError: If using all scalar values, you must pass an index

– Carlos Carvalho
Mar 8 at 23:12














That's simply perfect. You're great.Thank you

– Carlos Carvalho
Mar 9 at 0:16






That's simply perfect. You're great.Thank you

– Carlos Carvalho
Mar 9 at 0:16




















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%2f55071808%2fattributeerror-str-object-has-no-attribute-copy-from-user-input%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

AWS Lex not identifying response if by a variable 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 experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

Алба-Юлія

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