How to create a new column with .size() values of other column in pandas?

Farooq Sk
 df2 = df_cleaned.groupby('company').size()
 df2.columns = ['company', 'frequency']
 #df2.sort_values('frequency') # error : No axis named frequency for object type <class 'type'>
 df2

I have a dataframe "df_cleaned" with a 'company' column and im trying to create a new dataframe "df2" with a extra 'frequency' column to check how many times each company has been mentioned. I am unable to create a new frequency column. Seems like i'm doing something wrong, please help me out.

Screenshot showing no frequency column

ansev

Use:

df2 = df_cleaned.groupby('company').size().to_frame('frecuency')

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Pandas/Python: How to create new column based on values from other columns and apply extra condition to this new column

How to create a logic in pandas to create a new column based on existing values in other column?

Pandas dataframe, how to create a new totals column containing values based on other column

How to create new column with nuniqe values per ID in other column and do not count defined value in Python Pandas?

How to create new column based on values after "/" in other column in Oracle?

How to create new pandas column based on other column of data frame?

create new column group by values of other column

Pandas: Create New Column using Values in Subgroup of Other Columns

Pandas: Create a new column that alternate between values in two other columns

Pandas - create new column from values in other columns on condition

Pandas : Create new column based on text values of other columns

Grouping a column based on values on other columns to create new columns in pandas

How to create a new dataframe column using values and groupings from other rows and columns in pandas?

How to create a new column based on values from other columns in a Pandas DataFrame

Pandas: How to create a new column in a Dataframe and add values in it considering other existing columns

How to create a new column in a DataFrame based on values of two other columns

How to create a new column with values from comparing two other columns?

How to create a new column for difference of value conditionated to other row values

How to create new column in DataFrame based on other columns in Python Pandas?

Pandas: How to create a new column by random seletct other columns?

Create new column based on values in other columns

Pandas create new column with values from other columns, selected based on column value

How to Create New Column in Pandas?

How to create new column with new names that has value from other column and keep values for the previous columns?

How to create a new rows from column values of pandas data frame

How to create new columns in pandas dataframe using column values?

How to create a new column in a pandas data frame for values with the same index

How to create a new column in a pandas dataframe based on values from a loop?

Create a new column based on other column names and values