I have a list of sub-categories that correspond to a particular category, think of it like this: Category Sub Category a | 1 a | 2 a | 3 b | 4 b | 5 etc… I was wondering the best way to apply the Category value to each row of the dataframe (~800,000 rows) based on the Sub Category
Tag: dataframe
Find the row offset for the maximum value over the next N rows in Pandas?
I have some data in a Pandas DataFrame: and I am trying to get the offset for the maximum of the next N rows. For example, when ****, the output would look like I can get the value of the maximum over the next N rows using: However, is it possible to get the row offset position for the maximum
I cannot parse this xml file in python
I am trying to create an API connection and response is looking like below. I need to parse this data and turn it into a pd dataframe and/or create loop to find specific information belong to tags. Below is the code i try to run but it returns with empty list, and it looks not iterable. Also it is not
Transform DataFrame: place values in right columns as new rows
I am analyzing a consumer survey and there are both Dutch (NL) and French (FR) respondents. Depending on the answer they gave when we asked about their mother language they got the same questionnaire but translated in Dutch or French. The problem is that the output of Qualtrics (the survey software) gave us t…
pandas: manage duplicated sentences on different columns
I have a dataframe as follows: I want to add the first column value to a sentence if that sentence is repeated somewhere else in the next three columns. so my desired output would be col1 col2 col3 col4 1_a 1_aJoe waited for the train. the weather is nice the house looks amazing 2_a The train was late. the we…
Pandas groupby, assign and to_excel – on loop/repeat
I have a dataframe like as shown below My objective is to do the below a) Group columns based on multiple criteria (as shown in below code) b) Assign a default value based on target column. (ex: if target_at50, then assign value 50, if target_at60, then assign 60. if target_at70, then assign 70) b) Repeat the…
cannot search value in dataframe althought the value exists
I have a data frame with location data. I know a value for a certain location exists and I even know its index location. When I search using index location the values is shown correctly but if I search using a combination of other columns(lat and lon), the value does not show. I am attaching the screenshot be…
How to write a for-loop/if-statement for a dataframe (integer) column
I have a dataframe with a column of integers that symbolise birthyears. Each row has 20xx or 19xx in it but some rows have only the xx part. What I wanna do is add 19 in front of those numbers with only 2 “elemets” if the integer is bigger than 22(starting from 0), or/and add 20 infront of those t…
Python – Unable to export sql result to Excel
I want to export sql query result to excel file using Python. I queried the DB and able to retrieve the result set.Currently what im facing is like.Not able write the query result to Excel, Here is my Code, When im running this code,its skipping to the except block.Is there anyway to figure out the issue? …
How do I find first and last value of each day in pandas dataframe
I have a pandas DataFrame like the below: Price Date 25149.570 2/5/2017 14:22 24799.680 2/5/2017 14:22 24799.680 2/5/2017 14:22 14570.000 2/5/2017 14:47 14570.001 2/5/2017 14:47 14570.001 2/5/2017 14:47 14570.000 2/5/2017 15:01 14570.001 2/5/2017 15:01 14570.001 2/5/2017 15:01 14600.000 2/6/2017 17:49 14600.0…