Forum

Notifications
Clear all

Python data Science Toolbox (Part 2)  

   RSS

0

Did anyone run into this problem?

I am not able to plot the scatter chart for the two DF columns 'Year' and 'Total Urban Population', even though I can see that they match up.  What am I doing wrongly? I keep getting the error 'function' object has no attribute 'lower'.

# Code from previous exercise
urb_pop_reader = pd.read_csv('ind_pop_data.csv', chunksize=1000)
df_urb_pop = next(urb_pop_reader)
print("df_urb_pop:",df_urb_pop)

df_pop_ceb = df_urb_pop[df_urb_pop['CountryCode'] == 'CEB']
pops = zip(df_pop_ceb['Total Population'],
df_pop_ceb['Urban population (% of total)'])
pops_list = list(pops)
print("pops_list:",pops_list)

# Use list comprehension to create new DataFrame column 'Total Urban Population'
df_pop_ceb['Total Urban Population'] = [int(a*b/100) for (a,b) in pops_list ]

Urban_pop_df = df_pop_ceb['Total Urban Population']
print("Total Urban Population df:",Urban_pop_df)

year_df = df_pop_ceb['Year']
print("Year column df:",year_df)

# Try merging both DFs for 'Year' and 'Total Urban Population'
combined_Year_Urbanpop_df = pd.concat([year_df,Urban_pop_df], axis=1)
print("combined_Year_Urbanpop_df:",combined_Year_Urbanpop_df)

# Plot urban population data
df_pop_ceb.plot(kind=plt.scatter, x=combined_Year_Urbanpop_df['Year'], y=combined_Year_Urbanpop_df['Total Urban Population'])
plt.show()

 

OUTPUT>

pops_list: [

(91401583.0, 44.5079211390026),

(92237118.0, 45.206665319194),

(93014890.0, 45.866564696018),

(93845749.0, 46.5340927663649),

(94722599.0, 47.2087429803526)]

Total Urban Population df:

2 40680944
244 41697325
486 42662734
728 43670267
970 44717348
Name: Total Urban Population, dtype: int64

Year column df:

2 1960
244 1961
486 1962
728 1963
970 1964
Name: Year, dtype: int64

combined_Year_Urbanpop_df: Year Total Urban Population

2 1960 40680944
244 1961 41697325
486 1962 42662734
728 1963 43670267
970 1964 44717348

Traceback (most recent call last):
File "", line 26, in
df_pop_ceb.plot(kind=plt.scatter, x=combined_Year_Urbanpop_df['Year'], y=combined_Year_Urbanpop_df['Total Urban Population'])File "", line 2942, in __call__
sort_columns=sort_columns, **kwds)
File "", line 1973, in plot_frame
**kwds)
File "", line 1731, in _plot
kind = _get_standard_kind(kind.lower().strip())
AttributeError: 'function' object has no attribute 'lower'

Share:

Delete your account