[Solved] Scrape Multiple URLs from CSV using Beautiful Soup & Python

Assuming that your urls.csv file look like: https://stackoverflow.com;code site; https://steemit.com;block chain social site; The following code will work: #!/usr/bin/python # -*- coding: utf-8 -*- from bs4 import BeautifulSoup #required to parse html import requests #required to make request #read file with open(‘urls.csv’,’r’) as f: csv_raw_cont=f.read() #split by line split_csv=csv_raw_cont.split(‘\n’) #remove empty line split_csv.remove(”) #specify separator … Read more

[Solved] Row Average CSV Python

You can use the csv library to read the file. It is then just a case of calculating the averages: import csv with open(‘example.csv’) as handle: reader = csv.reader(handle) next(reader, None) for row in reader: user, *scores = row average = sum([int(score) for score in scores]) / len(scores) print ( “{user} has average of {average}”.format(user=user, … Read more

[Solved] How to insert character in csv cell in python?

You can tell Python’s split() to stop after a given number of matches by passing a maxsplit parameter. So in your case you just need to split after the first space as follows: import csv with open(‘input.csv’, ‘rb’) as f_input, open(‘output.csv’, ‘wb’) as f_output: csv_output = csv.writer(f_output, delimiter=”;”) for row in csv.reader(f_input, delimiter=”;”): # Skip … Read more

[Solved] Convert several YAML files to CSV

I would make use of a Python YAML library to help with doing that. This could be installed using: pip install pyyaml The files you have given could then be converted to CSV as follows: import csv import yaml fieldnames = [‘Name’, ‘Author’, ‘Written’, ‘About’, ‘Body’] with open(‘output.csv’, ‘w’, newline=””) as f_output: csv_output = csv.DictWriter(f_output, … Read more

[Solved] ‘IndexError: list index out of range’ – reading & writing from same csv file [closed]

For anyone who has the same problem in the future, the solution is to remove the extra line. writer=csv.DictWriter(f,fieldnames=fieldnames, lineterminator=”\n”) Although it can be read with the extra line spacing by changing This: namesList = [x[0] for x in people] To this: namesList = [x[0:1] for x in people] (in my example) blank results are … Read more

[Solved] Transform xlsx to CSV [closed]

It is no way to do it or at least not an easy one (like a simple script or command). Maybe by working on that xml files (Nahuel Fouilleul answer) but it will take too much time. jugging by reception alone of the question it looks like people donĀ“t want to touch this issue even … Read more

[Solved] Skipp the error while scraping a list of urls form a csv

Here is working version, from bs4 import BeautifulSoup import requests import csv with open(‘urls.csv’, ‘r’) as csvFile, open(‘results.csv’, ‘w’, newline=””) as results: reader = csv.reader(csvFile, delimiter=”;”) writer = csv.writer(results) for row in reader: # get the url url = row[0] # fetch content from server html = requests.get(url).content # soup fetched content soup = BeautifulSoup(html, … Read more

[Solved] open csv file in python to customize dictionary [duplicate]

First, do you know about the csv module? If not, read the introduction and examples to the point where you know how to get an iterable of rows. Print each one out, and they’ll look something like this: [‘AVNIVGYSNAQGVDY’, ‘123431’, ‘27.0’, ‘Tetramer’] Or, if you use a DictReader: {‘Epitope’: ‘AVNIVGYSNAQGVDY’, ‘ID’: ‘123431’, ‘Frequency’: ‘27.0’, ‘Assay’: … Read more

[Solved] How to write a python code which copies a unique column from an output file to a .csv file

There are a couple of ways you can do this. The best option is probably the python module for .csv operations. An example taken from the docs is: import csv with open(‘some.csv’, ‘wb’) as f: writer = csv.writer(f) writer.writerows(someiterable) Hope this helped. solved How to write a python code which copies a unique column from … Read more

[Solved] i have developed the program and i am facing problems in it

You can try to pivot the table. Which may give the format you require. Considering the information you gave as as ActionsOnly.csv userId,movieId,rating 18,9,3 32,204,4 49,2817,1 62,160438,4 70,667,5 73,1599,1 73,4441,3 73,4614,3.5 73,86142,4 95,4636,2 103,71,1 118,3769,4 150,4866,2 You wan to find out what user rated what movie out of 5. The userId is the index column, … Read more

[Solved] Combining csv files in R to different columns [closed]

Here’s an option. It’s more or less handcrafted as I’m not aware of any single command to do this exactly as you’ve specified. # the working directory contains d1.csv, d2.csv, d3.csv with # matching first two columns. The third column is random data read.csv(“./d1.csv”) #> a b c #> 1 1 A 0.5526777 #> 2 … Read more