-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpandas_html1.py
More file actions
32 lines (24 loc) · 838 Bytes
/
pandas_html1.py
File metadata and controls
32 lines (24 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import pandas as pd
import numpy as np
if __name__ == '__main__':
p = 'https://en.wikipedia.org/wiki/COVID-19_pandemic_by_country_and_territory'
wiki_data = pd.read_html(p)
print(f'Número tabelas: {len(wiki_data)}')
for i in range(10):
print(wiki_data[i].head(2))
# A tabela 9 parece de interesse
print(wiki_data[9].head())
print('')
print(f'Colunas: {wiki_data[9].columns}')
# Ou simplesmente:
wiki_data[9]
wiki_data[9].iloc[:, 0]
wiki_data[9].loc[13]
# Drop com número index e axis=0 linha
mm = wiki_data[12]
mm = mm.drop(217, axis=0)
mm = mm.dropna(subset=['Deaths'])
mm['Deaths'] = pd.to_numeric(mm['Deaths']) # , errors='coerce'
mm['Deaths'] = mm['Deaths'].replace('', '0')
mm['Deaths'] = mm['Deaths'].astype(int)
mm['Deaths'].sum()