此程序输出一个包含两列的表。我可以指定要显示的列吗?
def main():
bulletins = os.listdir(INPUT_DATA_DIR)
df = pd.DataFrame(bulletins)
df.columns = ['filename']
df['html'] = df.filename.apply(read_file)
print(df.head())
def get_document_id(page):
soup = BeautifulSoup(page, 'lxml')
div = soup.find('div')
print(div)
def read_file(filename):
with open(INPUT_DATA_DIR / filename,'r') as f:
data = f.read()
return data
现在我有两列,将来还会有更多。我只能输出某些列吗?例如,我可以输出前两列吗?
此刻我有这张桌子:
filename html
0 support.hpe.com-hpesc-public-api-document-c008... <!DOCTYPE html><html xmlns:msxsl="urn:schemas-...
1 support.hpe.com-hpesc-public-api-document-c043... <!DOCTYPE html><html xmlns:msxsl="urn:schemas-...
2 support.hpe.com-hpesc-public-api-document-c008... <!DOCTYPE html><html xmlns:msxsl="urn:schemas-...
3 support.hpe.com-hpesc-public-api-document-c007... <!DOCTYPE html><html xmlns:msxsl="urn:schemas-...
4 support.hpe.com-hpesc-public-api-document-c018... <!DOCTYPE html><html xmlns:msxsl="urn:schemas-...
.. ... ...
442 support.hpe.com-hpesc-public-api-document-c009... <!DOCTYPE html><html xmlns:msxsl="urn:schemas-...
443 support.hpe.com-hpesc-public-api-document-c021... <!DOCTYPE html><html xmlns:msxsl="urn:schemas-...
444 support.hpe.com-hpesc-public-api-document-c009... <!DOCTYPE html><html xmlns:msxsl="urn:schemas-...
445 support.hpe.com-hpesc-public-api-document-c008... <!DOCTYPE html><html xmlns:msxsl="urn:schemas-...
446 support.hpe.com-hpesc-public-api-document-c008... <!DOCTYPE html><html xmlns:msxsl="urn:schemas-...
[447 rows x 2 columns]