to_csv is a method on DataFrame, so I think you meant dataset.to_csv instead of pd.DataFrame.to_csv in the last two lines.
to_csv is a method on DataFrame, so I think you meant dataset.to_csv instead of pd.DataFrame.to_csv in the last two lines.
pd.Dataframe is the data frame class, not an instance. to_csv is intended to be an instance method, called from an instance. If you call it as a class method (as you did), its first argument must be a data frame.
Either of these should work:
dataset.to_csv(r'file path ...) # This is the intended use
pd.DataFrame.to_csv(dataset, r'file path ...) # Harder to read and more prone to error
I have a table with "pandas.core.frame.DataFrameIn" type.
I want to convert the dataframe for work on it.
I used to_frame() but I get the error: 'DataFrame' object has no attribute 'to_frame'
python - 'DataFrame' object has no attribute 'to_frame' - Stack Overflow
'DataFrame' object has no attribute 'to_dataframe' - Data Science Stack Exchange
python - AttributeError: 'Image' object has no attribute 'frame' - Stack Overflow
AttributeError: 'str' object has no attribute 'to' - fastai dev - fast.ai Course Forums
Check print(type(miss)) it should be <class 'pandas.core.series.Series'>
You have is dataframe, somewhere in the code you are doing wrong.
df = pd.DataFrame()
df.to_frame()
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Users\UR_NAME\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\generic.py", line 3614, in __getattr__
return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'to_frame'
I traced the tutorial, and below is the order flow
train = pd.read_csv("train.csv")
print(type(train)) # <class 'pandas.core.frame.DataFrame'>
miss = train.isnull().sum()/len(train)
print(type(miss)) # <class 'pandas.core.series.Series'>
miss = train.isnull().sum()/len(train) converts in into pandas.core.series.Series from pandas.core.frame.DataFrame
You are probably messed code at this place.
If you use Notebook while the current cell is running, "miss" is converted to a data frame so that the output is displayed the first time. If you run the cell again, you will get an/the error because it is already a data frame. So run the previous cell again and then run the current cell to fix the problem. The notebook itself works this way.
The function pd.read_csv() is already a DataFrame and thus that kind of object does not support calling .to_dataframe().
You can check the type of your variable ds using print(type(ds)), you will see that it is a pandas DataFrame type.
According to what I understand. You are loading loanapp_c.csv in ds using this code:
ds = pd.read_csv('desktop/python ML/loanapp_c.csv')
ds over here is a DataFrame object. What you are doing is calling to_dataframe on an object which a DataFrame already.
Removing this dataset = ds.to_dataframe() from your code should solve the error
There is something wrong with this function. It shows no errors, but when I try to run it, It says AttributeError: 'str' object has no attribute 'current'. (BTW, i am trying to run it as a flet on spyder)
def leapyears(e):
days_in_month = {1: 31, 3: 31, 4: 30, 5:31, 6: 30, 7: 31, 8: 31, 9: 30, 10: 31, 11: 30, 12: 31 }
month = int(EnterMonth_text.value)
year = int(EnterYear_text.value)
if year % 100 == 0:
if year % 400 == 0:
leap_year = True
elif year % 4 == 0:
leap_year = True
else:
leap_year = False
if month == 2 :
if leap_year:
days_in_month[2] = 29
else:
days_in_month[2]= 28
output_textfield.value= days_in_month[month]
page.update()
I think the order of the parameters doesn't match
When the function is declared create_and_run_model(name, state) name is fiirst and state is second
When the function is called model_ny = create_and_run_model(states, "NY") state seems to be first and name second
Edited as per comment:
You are passing the said dataframe "NY" as a string though. That's why calling positive on it also fails. Also name doesn't seem to be used. If you just want to call the dataframe that contains ONLY "NY" then you can filter it something like NY = states[['NY']] or use states[['NY']] as an argument instead of "NY".
And get rid of name as it is not used and if you don't intend to use it
The function create_and_run_model accepts two positional arguments name and state, but never makes any use of name. So maybe you should just remove the first argument from the function definition like this:
def create_and_run_model(state):
confirmed = state.positive.diff().dropna()
And than don't use it in create_and_run_model function calls:
model_ny = create_and_run_model(states.loc['NY'])
states.loc[''] will allow you to select specific state from the dataframe.
I have some experience with programming in Java, C++, etc. and I am trying to write a simple "To-Do List" program to get used to Python. I'm running into the error: str object has no attribute "completed" when trying to iterate over the list of tasks, check their completion status, and display them.
Here are some relevant pieces of the program:
Constructor for the Task class
def __init__(self, task_name):
self.task_name = task_name
self.completed = False
In the ToDoList class (which holds a list of the task instances created by the user) this is the iteration throwing the error in question:
for idx, task in enumerate(self.tasks, start=1):
status = "Completed" if task.completed else "Incomplete"
print(f"{idx}. {task.task_name} - {status}")
I thought, potentially the problem lies in the fact that the enumerate function is grabbing the string value of the task instance, rather than the object itself, so maybe I can iterate over it the old fashioned way and get around it. So I tried it like this:
counter = 1
for task in self.tasks:
status = "Completed" if task.completed else "Incomplete"
print(f"{counter}. {task.task_name} - {status}")
counter += 1
Yet, it throws the same error. I know there is something I am missing or not understanding correctly here. What is it?
Thanks!