Apply aggregation to the grouped result first. for instance, dfgrp1 what does it produces when you print it? an object reference, which you cannot make into frame. However, the result that you see as result of groupby, employing agregation, will allow you to use to_frame()
Answer from Naveed on Stack Overflow'DataFrame' object has no attribute 'to_dataframe' - Data Science Stack Exchange
python - AttributeError: 'DataFrame' object has no attribute 'group' - Stack Overflow
'DataFrame' object has no attribute 'to_frame'
Pandas AttributeError: 'DataFrame' object has no attribute 'group_by'
I mean, isn't it groupby(), not group_by()?
More on reddit.comThe 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
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'
Hello,
Has anyone ever come across this before?
I'm trying to group some data in a dataframe and getting this error. The steps I've taken are:
-
in a for loop:
read in a csv from an api using pd.read_csv() replaced some values in a column using a for loop and .loc[] appended the resulting data frame to a list
2) concatenated the list of dataframes using pd.concat()
3) added a calculated column to the new DF by multiplying another column
4) added two empty columns
5) filtered the DF using .loc[] based on a value within a column
6) filtered the DF using .loc[] based on a value in a different column
7) tried to use this code:
new_DF = old_df.group_by(['col1', 'col_2', 'col_3', 'adgroup', 'col_4', 'col5', 'col6'], as_index=False)[['col7', 'col8', 'col9']].sum()
The DF seems to behaving normally for example I can do dtypes and columns on it and add columns which are calculated from other columns. What is super frustrating is that I can do pd.to_csv() and then pd.read_csv() on the DF and then I'm able to do the grouping I want (however this isn't ideal which is why I'm posting).
Any advice would be appreciated.
Cheers