python-3.x - 打印特定列。熊猫数据框
问题描述
该程序输出一个包含两列的表。我可以指定要显示哪些列吗?
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]
解决方案
推荐阅读
- apache-spark - 如何使用 spark 插入 HDFS?
- google-cloud-platform - Ansible gcp_compute 库存插件 - 基于机器名称的组
- android - 生成签名 apk 时出错:请指定签名 apk 的目标文件夹
- powershell - 如何在 Powershell 中同时调用一组 REST API?
- wordpress - WooCommerce 不显示子类别
- php - 如何在 Laravel 中获取查询生成器结果的所有列的数组?
- arrays - 运行时错误 9“下标超出范围”数组 redim 保留 vba
- c - 打印语句不适用于 Mac 的 CodeBlocks
- android - 如何导入 WorkManager 类
- asp.net - 在 ListView ItemTemplate 中设置按钮属性