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
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 expectingdfname
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
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
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 expectingdfname
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
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 expectingdfname
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
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
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