I’m trying to get prices of crypto pairs that are on text file. The pairs are written only one pair by line, so every new line has one pair. my code is: When i run this code only first pair in file is printed and then I get a lot of errors from Binance client.py, the last error is: APIError(code=-1100):
Tag: loops
Avoid ValueError outside a while loop?
In the second line, I am trying to make it not crash if a string is entered but can’t find a way to use an exception or something similar. In the while loop it works normally as the exception deals with this case. Answer while followed by a variable condition often ends up with bugs/repeating code => bad maintenability. Use
Iterating Through List of Lists, Maintaining List Structure
Say I have the following list of list of names: I want to return only the “Matts” in the list, but I also want to maintain the list of list structure. So I want to return: I’ve something like this, but this will append everthting together in one big list: I know something like this is possible, but I want
Create array of differences in col between two adjacent numbers in an array python/pyspark
I have a column of arrays made of numbers, ie [0,80,160,220], and would like to create a column of arrays of the differences between adjacent terms, ie [80,80,60] Does anyone have an idea how to approach this in Python or PySpark? I’m thinking of something iterative (ith term minus i-1th term starting at second term) but am really stuck how
Why doesn’t the break statement work in this program?
My program is supposed to tell users how many months it will take to double the money in their investment account. I am able to do the calculations correctly, but I’m unable to break out of the loop and print the statement that tells the user the final sentence “It will take x months to double your investment with a
python pandas pulling two values out of the same column
What I have is a basic dataframe that I want to pull two values out of, based on index position. So for this: first_column second_column 1 1 2 2 3 3 4 4 5 5 I want to extract the values in row 1 and row 2 (1 2) out of first_column, then extract values in row 2 and row
How to make column value categories and add to a new column?
I have a dataframe with Heart rate values ranging 0-280 in one column. I am making categories and adding them to a new column as follows: This is a hectic task and need more line of code. Is there any way I can do the same using Loops in Python? Answer Just use a one-liner:
Loop does not iterate over all data
I have code that produces the following df as output: I built a for loop to iterate over all the elements in the ‘keyword’ column and put them separately into a new df called df1. The loop look like this: The output it produces is: Although the for loop works fine, it does not iterate over all the rows from
What is the difference between normal loops and list comprehension?
The result for line 2 is is something like: Where as the result for the normal for loop is: Why do I get the extra [None, None, None, None] in case of list comprehension? Answer A list comprehension is used to comprehend (Make) a list. It is useful only when making lists. However, here you are not making a list,
Using a for loop with beautiful soup and if statements to populate a dataframe
Goal: The goal of my project is to use BeautifulSoup aka bs4 to scrape only necessary data from an HTML file and import it into excel. The html file is heavily formatted so unfortunately I haven’t been able to tailor more common solutions to my needs. What I have tried: I have been able to parse the HTML file to