简体   繁体   中英

I am trying to extract a specific column from a html table using pandas

import quandl
import pandas as pd
fiddy_states = pd.read_html('https://www.infoplease.com/us/postal-information/state-abbreviations-and-state-postal-codes')
print(fiddy_states[0][0])

I am getting an error which I am not able to understand. Since I am new to this I can't find the solution. I just want the zip code column from the table in the url.

Try any of Web Scraping tools like beautiful soup or selenium. and the question itself is unclear. tell me why are you using pandas for HTML page. if you are want to extract a coloumn from a web page here is a solution already available.

The Link you provided has two table - hence two corresponding dataframe.

You can get them by:

import quandl
import pandas as pd
fiddy_states = pd.read_html('https://www.infoplease.com/us/postal-information/state-abbreviations-and-state-postal-codes')
# First Table
fiddy_states[0]['Postal Code']
# Second Table
fiddy_states[1]['Postal Code']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM