I have a question about deleting columns after grouping Python Pandas data.

Asked 2 years ago, Updated 2 years ago, 120 views

%matplotlib inline
import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import os

data_filename = 'Popular_Baby_Names'
data = pd.read_csv("C:/Anaconda3/DataSet/Popular_Baby_Names.csv", index_col='Gender')

data2 =data.rename(columns={"Year of Birth":"YoB"},inplace=True)
data2

groups = data.groupby(data.Ethnicity)
groups
groups.sum()

I'm dealing with a CSV file.

The plot is the execution result. I'm going to erase the columns of YOB and Rank to graph the number of each race here.

del data2["Rank"]

If you try to erase Rank and YoB as above, the error 'NoneType' object does not support item deletion appears, but I don't know what the problem is Help me

python data pandas

2022-09-22 13:44

1 Answers

groups = data[['Count']].groupby(data.Ethnicity)

You can select series using [] as shown above.

Check out the link below (azure notebook).

https://notebooks.azure.com/wincommerce/projects/pandas-indexing-and-matplotlib/html/hashcode_8012.ipynb


2022-09-22 13:44

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.