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

Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page

Posting a File and Associated Data to a RESTful WebService preferably as JSON2019 Community Moderator ElectionREST URI convention - Singular or plural name of resource while creating itUploading both data and files in one form using Ajax?How do I upload a file with metadata using a REST web service?REST API - file (ie images) processing - best practicesSpring: JSON data and file in the same requestREST API Put large dataPosting a file and JSON data to Spring rest serviceRESTful Web Service Upload/Download Large Data With JSONREST API Design sending JSON data and a file to the api in same requestPost JSONArray to REST servicePUT vs. POST in RESTParsing values from a JSON file?JavaScript/jQuery to download file via POST with JSON dataHow do I upload a file with metadata using a REST web service?How to POST JSON data with Curl from Terminal/Commandline to Test Spring REST?Separate REST JSON API server and client?what's the correct way to send a file from REST web service to client?How do I write JSON data to a file?What is “406-Not Acceptable Response” in HTTP?REST API - file (ie images) processing - best practices