I have a DataFrame df_data: I have a function and parameter like this: Explain Parameters: with CustID = 1 the parameters should be list_minor = [3,1] (position is not important), list_major = [1] because with LocationID = 324 he get 3 times and LocationID = 490 he get 1 time (324,490 gets isMajor = 0 so it should be into
Tag: pandas
How to select top n columns from time series data instead of using nlargest in pandas?
I have weekly based trade export time-series data that I need to make a stacked bar plot for visualizing trade activity. To do so, I aggregated my data for sum-up of each columns for all rows, then use nlargest() to select top n columns. However, doing this way might not be quite accurate because I made stacked plot for different
Contracted nodes automatically in Networkx
I have problem, I wish could automatically merge the nodes by inserting an if condition. I have this dataframe: I created this graph: What I would like is to merge the nodes with Weight <15 and not taking the nodes 10.0.11.100,10.0.12.100,10.0.13.100,10.0.14.100 using an if condition. I tried with this code: But it does not work. I wish it were all
How to assign a value to a column for a subset of dataframe based on a condition in Pandas?
I have a data frame: df: index A class label 0 4 0 0 1 5 1 0 2 6 0 0 3 7 1 0 I want to change the label to 1, if the mean of A column of rows with class 0 is bigger than the mean of all data in column A? How to do this
Plotly: How to display a regression line for one variable against multiple other time series?
With a dataset such as time series for various stocks, how can you easily display a regression line for one variable against all others and quickly define a few aesthetic elements such as: which variable to plot against the others, theme color for the figure, colorscale for the traces type of trendline; linear or non-linear? Data: Reproducible through: Answer The
How to convert a list with dictionaries into new pandas columns?
I have a dataframe which has a list of dictionaries as a column: This column has the following format: How can I convert this column into 4 new columns? I mean: route_id (x2), stop_id(x2) as new columns. Thanks in advance! Answer You can use df.explode with df.apply:
How to create files from a groupby object, based on the length of the dataframe
I have a dataframe (df) that looks like this (highly simplified): The ‘VALUE’ column contains a variable number of rows with identical values. I am trying to output a series of csv files that contain all of the rows that contain a ‘VALUE’ length == 2, ==3 etc. For example: I can get the desired output of one length value
Transpose 3 column excel with K:V into column Pandas
I have a 3 column excel file I’m reading into pandas with basically k:v pairs in columns I need to not only tie the information in unnamed:1 & unnamed:2 to the unique animal ID as this is how I will track the animal but also transpose these columns where everything to the left of the “:” is the column header
Creating a new column if a condition is satisfied in the last N days python pandas
I have a dataframe like this: timestamp value id. 2020-12-16 25 1 2020-12-17 45 1 2020-12-31 40 1 2021-01-31 37 1 2020-12-15 12 2 2020-12-16 78. 2. I want to create a new column outcome which takes a value yes is the id doesn’t have any entry for the last 25 days. For e.g., this is the expected output timestamp
Check if Dataframe is empty and print results
I would like to go over an excel file with different stock symbols. How can I check after reading the stocks values (Open,Close,High,Low,Volume) in a dataframe with yahoo, if the dataframe is empty? In this excel list are more than 700 Symbols and some times yahoo have no data for some symbols. So I would like to exclude this symbols,