Nov-13-2023, 08:10 PM
Hi all,
I'm trying to convert two columns ('BIRTH_YEAR', 'NAME') of baby_names into a dictionary. Why does the newly-formed dictionary only consist of the last df row of each year?
I'm trying to convert two columns ('BIRTH_YEAR', 'NAME') of baby_names into a dictionary. Why does the newly-formed dictionary only consist of the last df row of each year?
baby_name_dict = {} print(baby_names.info(), '\n') baby_name_dict = dict(zip(baby_names.BIRTH_YEAR, baby_names.NAME)) print(f'baby_name_dict is: {baby_name_dict}.')
Output:<class 'pandas.core.frame.DataFrame'>
RangeIndex: 13962 entries, 0 to 13961
Data columns (total 6 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 BIRTH_YEAR 13962 non-null int64
1 GENDER 13962 non-null object
2 ETHNICTY 13962 non-null object
3 NAME 13962 non-null object
4 COUNT 13962 non-null int64
5 RANK 13962 non-null int64
dtypes: int64(3), object(3)
memory usage: 654.6+ KB
None
baby_name_dict is: {2011: 'ZEV', 2012: 'ZEV', 2013: 'Zev', 2014: 'Zev'}.
Getting myself ready for a really foolish oversight... :)