[Solved] returning only the first Value while i am printing a list [closed]

Indent the business and append line so it is inside the for loop: for item in data: phone_url = “https://yellowpages.com.eg” + item[“data-tooltip-phones”] title = item.find_previous(class_=”item-title”).text address = item.find_previous(class_=”address-text”).text.strip().replace(‘\n’, ”) phones = requests.get(phone_url).json() business = { ‘name’: title, ‘address’: address, ‘telephone’: phones } my_list.append(business) solved returning only the first Value while i am printing a list … Read more

[Solved] Group by ID and select rows with the newest DATE1 and the oldest DATE2

IIUC, this is a classical groupby+agg. You need to set the dates to a datetime type for meaningful comparisons: (df .assign(DATE_1=pd.to_datetime(df[‘DATE_1’]), DATE_2=pd.to_datetime(df[‘DATE_2’]) ) .groupby(‘ID’) .agg({‘DATE_1’: ‘min’, ‘DATE_2’: ‘max’}) ) output: DATE_1 DATE_2 ID 12 2012-01-01 2021-01-01 13 2010-01-01 2021-01-01 14 2012-01-01 2021-01-01 0 solved Group by ID and select rows with the newest DATE1 and … Read more

[Solved] What are some Alternatives to enumerate function in Python?

Done without the enumerate function: (you can remove the other loop, and you don’t have to call return, python will automatically return None): def add_letter(mylist): for i in range(len(mylist)): mylist[i] = str(mylist[i]) + randomletter # Now you can call addletter function mylist = [1, 2, 3, 4, 5, 6, 7, 8, 9, ]; randomletter=”a” add_letter(mylist) … Read more

[Solved] What does the role and line_spoken do in code?

This is called tuple unpacking. a, b = 1, 2 print a # 1 print b # 2 line.split(…) returns two elements which get unpacked to role, line_spoken. So, for example if line.split(…) returns [‘Monty’, ‘Python’], role would get ‘Monty’ and line_spoken would get ‘Python’. solved What does the role and line_spoken do in code?

[Solved] Read in a csv file as a variable in python

Here a bare code that should do what you are asking: import tkinter as tk from tkinter import filedialog from tkinter import simpledialog import pandas as pd root = tk.Tk() root.withdraw() path = filedialog.askopenfilename(parent=root, filetypes=[(“CSV Files”,”.csv”)]) col1 = simpledialog.askstring(“Input”, “Column 1″, parent=root, initialvalue=”col1”) col2 = simpledialog.askstring(“Input”, “Column 2″, parent=root, initialvalue=”col2”) df = pd.read_csv(path, usecols=[col1, col2]) … Read more

[Solved] Matrix indexing combinations but one per row

Itertools has it: import itertools x = [ [1,2,3],[4,5,6],[7,8,9]] for y in list(itertools.product(*x)): print y it gives you: (1, 4, 7) (1, 4, 8) (1, 4, 9) (1, 5, 7) (1, 5, 8) (1, 5, 9) (1, 6, 7) … (3, 6, 9) 3 solved Matrix indexing combinations but one per row

[Solved] PDF Type Detection [closed]

You can convert the PDF to HTML format using PDFMiner. Then you can use beautifulsoup to find if it contains only <img> tag then it’s totally a scanned PDF, otherwise, if any text data found then it is electronic. Moreover, you can decide this based on the percentage of text extracted. 1 solved PDF Type … Read more