I have a pandas DataFrame with a structure like this: (to build it, do something like What would be the simplest way to turn it into a NumPy 3-dimensional array? This would be the expected result: I have tried several things, without success: Answer One option is to convert df to a list; then cast to numpy array: Output:
Tag: pandas
How can I make Matplotlib show all tick labels?
I am trying to plot some time series’ and I struggle with the tick labels. my df looks like this: The code to plot it looks like this: The plot however looks like this https://i.stack.imgur.com/tKqP6.png How can I make it thath it shows all years as x ticks? Thank you in advance Answer Try this: The output is: I used
Get the value corresponding to the start of a given category created with datetime64[ns]
I have a DataFrame that is a time series every minutes (duration: up to today) All ts are in datetime64[ns] Input: I create a new column with categorical data consisting of periods of 40 days like below: ( I am using pd.cut) , output is: The set of period is as below: [(2021-12-31 23:59:59.999999999, 2022-02-10] < (2022-02-10, 2022-03-22] < (2022-03-22,
Assign outcome from SQL query to column
I have a dataframe (test_df) that looks like this: I want to assign the result from executing the query in dq_sql to the column Results. I tried this: which results in: Strange thing is, the ‘X’ result should be assigned to row 1, whereas the query in row 0 does not seem to run. When I try to run the
Pandas: how select row based on string in previous row – should be a simple solution
I have a a csv file. How do I print the row that follows a row that has a particular string? I need to print all rows that contain “ixation” in them and then the row that follows this row. Here is my current code Here is my current output… But I want… How do I only print out the
Converting integer values to week (year-week format)
I am trying to convert one of the dataframes I have to year-week format to use it in my time series modeling, but I am not sure how would I be able to do this? Here is my code: Output- Desired O/p in week column should be in date time format. The datatype was an int in the 1st dataframe,
Animating two circles Python
I have a text file, with the coordinates of two circles on it. I want to produce a live animation of both particles. For some reason the following code crashes The text file that the data is taken from has the columns of X1, Y1, X2 and Y2 where X1 represents the x coordinate of the 1st particle etc. If
Constrained Multi-Linear Regression using Gekko
I have a multilinear regression problem where I have the prior information about the range of the output (dependent variable y) – The prediction must always lie in that range. I want to find the coefficients (upper and lower bound) of each feature (independent variables) in order to make the linear regression model restricted to the desired range of output.
How to find if if a particular column has zero value in a dataframe?
Trust you all are doing well! I have this dataframe that contains 0 and float numbers in column (‘BP_MOVE’) , there could be two conditions Zero in any row of column (‘BP_MOVE’) Zero in each row of column (‘BP_MOVE’) Below is what i have tried, the first python statement covers the second case very well where each row has 0
Checking overlaps between two columns of datetime type in Pandas DataFrame
I have a dataframe with two columns that are datetime objects (time_a and time_b). I need to check on a row-by-row basis if the elements of time_a or time_b for such row, are contained within any of the other intervals defined by the other time_a and time_b rows. That’s what I defined as ‘overlap’, if any period of work between