yesterday, when i run the commands for webscrapping using python i got error
My commands:
import pandas as pd
datas= pd.DataFrame({'president_name':president_names,'terms_of_office':term_of_office})
datas
Error:
Reason
when i run this seprately president_name and terms_of_office
import pandas as pd
datas= pd.DataFrame({'president_name':president_names})
datas
import pandas as pd
datas= pd.DataFrame({'terms_of_office':term_of_office})
datas
output
see in above output length is different president_name 18 row while terms_of_office 14 row
Solution
president_na = []
for item in president:
parts = item.split('\n')
if len(parts) > 1:
president_na.append(parts[0])
president_na
term_of = []
for item in president:
parts = item.split('\n')
if len(parts) > 1:
term_of.append(parts[1])
term_of
import pandas as pd
datas= pd.DataFrame({'president_name':president_na,'terms_of_office':term_of})
datas
Top comments (0)