The function digits, in the while loop – while (n > 0) returns 325 326 327 and 1 as the count value and if I use while (n > 1) it returns the correct number count. Any logical reason for this behavior? Answer There is a difference between / and //. / does the normal division given an accurate answer
Tag: if-statement
How to use pandas apply to replace iterrows?
I am calculating the sentiment value on every row in the dataset based on news headline. I used iterrows to achieve this: However, the processing time is taking too long (>30 minutes runtime and it is not done yet). I have 16.6k rows in my dataset. This is a small section of the dataset: I have read that iterrows is
python to get substring of an excel cell with a condition
I’m trying to concatenate several csv files and create a ‘DATE_TIME’ column based on the specific column ‘NAME’. I apply an IF condition for extract the substring of DATE_TIME from NAME based on the appearance of a string ‘RE’. Here’s my code: My question is at the IF-ELSE statement. They return the same position of the substring, so that I
Python: Determining period of the day based on hour using a for loop and conditionals
I would like to name the period of the day based on hourly information to my dataframe. For this, I am attempting the following: However, when double-checking if the length of my day_period list is the same as that of my dataframe (df)… they differ and they shouldn’t. I can’t spot the mistake. How can I fix the code? Here’s
Get value From Previous or Next Rows Based on Condition from two or more columns in Python
I am using Pandas Python to calculate timedelta between rows which when it uses previous or next rows is based on conditions. My table is like this sampel table I want to create timedelta column with this condition: it gets value from previous rows when STATUS > status_before and gets value from next rows when STATUS < status_after. I tried
Find Word in a csv file and implement it using loops
I am having a dataframe named df which is having two columns, Now what i am trying to implement is I am trying to find out company name where “gc” word exists and store it into new dataframe df1. but this code is showing error Answer The error you’re getting is because df[‘Company name’] is not iterable, you cannot index
if statement loops and while loops
I’m trying to create a loop and give clues of the number the user has to guess I first tried if statements and it of course didn’t loop and I tried multiple things this was the best I could come up with but it didn’t exactly work it would keep telling me for example: it was smaller but when it
Perform a list comprehension inside of a for loop in Python [closed]
Closed. This question needs debugging details. It is not currently accepting answers. Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question. Closed 1 year ago. Improve this question In short what I need is to get for each element from this
How can I have my input be typed out again via using while loops and if statements?
So i have this simple problem and I am not so sure what to do even after trying it for quite sometime. my issue is that I am not so sure what to type such that my input user has to type either yes or no instead of typing something else. Additionally, when I tried to run the program, when
python if/else and try/except combination without redundancy
While playing around with icecream I programmed the following lines of code As you can see I want to assign the (same) lambda expression to ic in both cases if not debugging the code or if importing icecream is not working I was wondering if there is a (maybe pythonic) way to handle that idea without redundancy. Answer You could