AttributeError: 'str' object has no attribute 'copy' from user inputUser 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

Is there a hemisphere-neutral way of specifying a season?

Why is consensus so controversial in Britain?

Why is it a bad idea to hire a hitman to eliminate most corrupt politicians?

How much of data wrangling is a data scientist's job?

Why does this cyclic subgroup have only 4 subgroups?

How does a predictive coding aid in lossless compression?

Intersection Puzzle

How do conventional missiles fly?

Is it acceptable for a professor to tell male students to not think that they are smarter than female students?

I would say: "You are another teacher", but she is a woman and I am a man

How could indestructible materials be used in power generation?

How to prevent "they're falling in love" trope

What do you call someone who asks many questions?

Size of subfigure fitting its content (tikzpicture)

What's the in-universe reasoning behind sorcerers needing material components?

Why didn't Miles's spider sense work before?

How dangerous is XSS?

Assassin's bullet with mercury

CAST throwing error when run in stored procedure but not when run as raw query

Expand and Contract

Do UK voters know if their MP will be the Speaker of the House?

Is it inappropriate for a student to attend their mentor's dissertation defense?

What are some good books on Machine Learning and AI like Krugman, Wells and Graddy's "Essentials of Economics"

Is it logically or scientifically possible to artificially send energy to the body?



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


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













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

1




1












  • 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

Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme