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;
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
add a comment |
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
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 expectingdfnameto 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
add a comment |
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
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
python pandas dataframe
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 expectingdfnameto 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
add a comment |
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 expectingdfnameto 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
add a comment |
1 Answer
1
active
oldest
votes
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
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
add a comment |
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%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
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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%2f55071808%2fattributeerror-str-object-has-no-attribute-copy-from-user-input%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
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
dfnameto 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