Tengo un archivo .csv como el siguiente:
start_date,end_date,pollster,sponsor,sample_size,population,party,subject,tracking,text,approve,disapprove,url
2020-02-02,2020-02-04,YouGov,Economist,1500,a,all,Trump,FALSE,Do you approve or disapprove of Donald Trump’s handling of the coronavirus outbreak?,42,29,https://d25d2506sfb94s.cloudfront.net/cumulus_uploads/document/73jqd6u5mv/econTabReport.pdf
2020-02-02,2020-02-04,YouGov,Economist,376,a,R,Trump,FALSE,Do you approve or disapprove of Donald Trump’s handling of the coronavirus outbreak?,75,6,https://d25d2506sfb94s.cloudfront.net/cumulus_uploads/document/73jqd6u5mv/econTabReport.pdf
2020-02-02,2020-02-04,YouGov,Economist,523,a,D,Trump,FALSE,Do you approve or disapprove of Donald Trump’s handling of the coronavirus outbreak?,21,51,https://d25d2506sfb94s.cloudfront.net/cumulus_uploads/document/73jqd6u5mv/econTabReport.pdf
2020-02-02,2020-02-04,YouGov,Economist,599,a,I,Trump,FALSE,Do you approve or disapprove of Donald Trump’s handling of the coronavirus outbreak?,39,25,https://d25d2506sfb94s.cloudfront.net/cumulus_uploads/document/73jqd6u5mv/econTabReport.pdf
2020-02-07,2020-02-09,Morning Consult,"",2200,a,all,Trump,FALSE,Do you approve or disapprove of the job each of the following is doing in handling the spread of coronavirus in the United States? President Donald Trump,57,22,https://morningconsult.com/wp-content/uploads/2020/02/200214_crosstabs_CORONAVIRUS_Adults_v4_JB.pdf
2020-02-07,2020-02-09,Morning Consult,"",684,a,R,Trump,FALSE,Do you approve or disapprove of the job each of the following is doing in handling the spread of coronavirus in the United States? President Donald Trump,88,4,https://morningconsult.com/wp-content/uploads/2020/02/200214_crosstabs_CORONAVIRUS_Adults_v4_JB.pdf
2020-02-07,2020-02-09,Morning Consult,"",817,a,D,Trump,FALSE,Do you approve or disapprove of the job each of the following is doing in handling the spread of coronavirus in the United States? President Donald Trump,37,37,https://morningconsult.com/wp-content/uploads/2020/02/200214_crosstabs_CORONAVIRUS_Adults_v4_JB.pdf
2020-02-07,2020-02-09,Morning Consult,"",700,a,I,Trump,FALSE,Do you approve or disapprove of the job each of the following is doing in handling the spread of coronavirus in the United States? President Donald Trump,50,22,https://morningconsult.com/wp-content/uploads/2020/02/200214_crosstabs_CORONAVIRUS_Adults_v4_JB.pdf
2020-02-07,2020-02-09,Morning Consult,Politico,1996,rv,all,Trump,FALSE,"And, do you approve or disapprove of how each of the following have handled the response to the coronavirus? President Trump",39,35,https://morningconsult.com/wp-content/uploads/2020/02/200213_crosstabs_POLITICO_RVs_v1_AUTO.pdf
2020-02-07,2020-02-09,Morning Consult,Politico,700,rv,R,Trump,FALSE,"And, do you approve or disapprove of how each of the following have handled the response to the coronavirus? President Trump",71,8,https://morningconsult.com/wp-content/uploads/2020/02/200213_crosstabs_POLITICO_RVs_v1_AUTO.pdf
2020-02-07,2020-02-09,Morning Consult,Politico,788,rv,D,Trump,FALSE,"And, do you approve or disapprove of how each of the following have handled the response to the coronavirus? President Trump",15,60,https://morningconsult.com/wp-content/uploads/2020/02/200213_crosstabs_POLITICO_RVs_v1_AUTO.pdf
2020-02-07,2020-02-09,Morning Consult,Politico,508,rv,I,Trump,FALSE,"And, do you approve or disapprove of how each of the following have handled the response to the coronavirus? President Trump",34,33,https://morningconsult.com/wp-content/uploads/2020/02/200213_crosstabs_POLITICO_RVs_v1_AUTO.pdf
Quiero contar el numero de veces que se repite la palabra "Huffington Post" y el numero de veces que hay URLs que sigan el patrón siguiente: Empiecen por http o https y acaben en .pdf
He realizado lo siguiente:
import csv
import re
path = "mipath"
with open(path, "r") as file1:
file1 = file1.read()
# Contamos el numero de occurrencias de Huffington Post
counter1 = file1.count('Huffington Post')
# Contamos el numero de occurrencias de urls terminadas en .pdf
occ = re.findall(r"(https?:\/\/.*\.pdf+$)", file1)
print('The pattern Huffington_Post appears', counter1, "times")
print(len(occ))
Sin embargo, obtengo lo siguiente:
The pattern Huffington_Post appears 112 times
1
No entiendo porque es 1 si le estoy diciendo que me encuentre todos los casos. Quizás deberia iterar por filas? No acabo de ver como. Gracias.
.csv
o tambien puede ser conpandas
?