Code object
Area_name object
Inner/_Outer_London object
NEET object
Score object
Noparents object
Familyoffwork float64
TeensPragnancy object
dtype: object
- Я пробовал несколько способов преобразования типа данных объекта в numeri c, но продолжаю получать ошибку.
school_df2['foreign'] = school_df2.foreign.astype(float)
Output: AttributeError: 'NoneType' object has no attribute 'foreign'
df1['foreign'] = school_df2['foreign'].str.astype(float)
Output: TypeError: 'NoneType' object is not subscriptable
school_df2=pd.to_numeric(school_df2['foreign'], errors='coerce')
Output: TypeError: 'NoneType' object is not subscriptable
school_df2['foreign'] = pd.to_numeric(school_df2['foreign'],errors='coerce')
Output: TypeError: 'NoneType' object is not subscriptable
import numpy as np
np.array(['foreign','NEET','Score', 'Noparents', 'Familyoffwork','TeensPragnancy' ]).astype(np.float)
Output: ValueError: could not convert string to float: 'foreign'
- Начало моего код следующий:
!wget -q -O 'london_data.csv' https://data.london.gov.uk/download/london-borough-profiles/c1693b82-68b1-44ee-beb2-3decf17dc1f8/london-borough-profiles.csv
print('Data downloaded!')
london_df = pd.read_csv('london_data.csv', encoding= 'unicode_escape')
london_df.head()
ldf=london_df.drop(['Turnout_at_2014_local_elections','Male_life_expectancy,_(2012-14)', 'Female_life_expectancy,_(2012-14)', 'Proportion_of_seats_won_by_Lib_Dems_in_2014_election', 'Proportion_of_seats_won_by_Labour_in_2014_election', 'Proportion_of_seats_won_by_Conservatives_in_2014_election', 'Political_control_in_council', 'Mortality_rate_from_causes_considered_preventable_2012/14', 'People_aged_17+_with_diabetes_(%)', 'Childhood_Obesity_Prevalance_(%)_2015/16', 'Ambulance_incidents_per_hundred_population_(2014)'], axis = 1)
ldf.head()
school_df = ldf [['Code', 'Area_name', 'Inner/_Outer_London','Proportion_of_16-18_year_olds_who_are_NEET_(%)_(2014)', 'Achievement_of_5_or_more_A*-_C_grades_at_GCSE_or_equivalent_including_English_and_Maths,_2013/14', 'Rates_of_Children_Looked_After_(2016)', '%_children_living_in_out-of-work_households_(2015)', 'Teenage_conception_rate_(2014)']]
school_df
school_df = school_df.rename(columns={'Proportion_of_16-18_year_olds_who_are_NEET_(%)_(2014)': 'NEET', 'Achievement_of_5_or_more_A*-_C_grades_at_GCSE_or_equivalent_including_English_and_Maths,_2013/14': 'Score','Rates_of_Children_Looked_After_(2016)': 'Noparents', '%_children_living_in_out-of-work_households_(2015)': 'Familyoffwork', 'Teenage_conception_rate_(2014)': 'TeensPragnancy'})
school_df
school_df1=school_df.drop(school_df.tail(5).index,inplace=True)
school_df1
school_df2=school_df.drop(school_df.head(1).index,inplace=True)
school_df2
school_df2.corr()
Familyoffwork
Familyoffwork 1.0
Может кто-нибудь сказать мне, почему я получаю эту ошибку?