I have a dataframe and I would like to find the n highest numbers in each column. There are a variety of methods to do this, but all seem to fail as a result of strings also being in the dataframe. I have tried a multitude of ways to get around this but I am always stumped by the presence
Tag: pandas
How to loop through elements from a python pandas dataframe to a new nested dictionary?
I am currently using pandas library to read data from a CSV file. The data includes a “data” column which consists of 1’s and 0’s, and a “published_at” column which has unique time and date stamps (I have converted it to become the index of the dataframe). Click here to see…
Is it possible to pass an extra argument to lambda function in pandas read_csv
I am using the read_csv() function from pandas and the option for a lambda date_parser function quit often and I am wondering if it is possible to pass an argument to this labda function. This is a minimal example where I set the format_string: I do know, that pandas has a infer_datetime_format flag, but this…
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all(). & [duplicate]
This question already has answers here: Python-pandas: the truth value of a series is ambiguous (2 answers) Closed 1 year ago. I have a dataframe ‘signal’: As I need some condition to set up my ‘_exec_dict’ which is a dictionary to tell the trading platform what my order is? The proble…
Split Series of tuples into multiple columns
I have a series of tuples of the form (‘Name’, Number), and I would like to split them into two columns, one being the name, the other being the number. I’d like to end up with something like this: I’ve tried a few iterations of splitting strings, applying a lambda function, etc, and c…
Longitude and Latitude Distance Calculation between 2 dataframes
I have the following two dataframes. Call this df1 and call this one df2 I want to know how I can calculate the distance between place and all cities listed. So it should look something like this. I’m reading through this particular post and attempting to adapt:Pandas Latitude-Longitude to distance betw…
Plot multiple lines in subplots
I’d like to plot lines from a 3D data frame, the third dimension being an extra level in the column index. But I can’t manage to either wrangle the data in a proper format or call the plot function appropriately. What I’m looking for is a plot where many series are plotted in subplots arrang…
ValueError: cannot convert a DataFrame with a non-unique MultiIndex into xarray
These are the data I want to convert which are saved in CSV. And some of the longitude and latitude may are repeated, actually, they are extracted from a NetCDF file. So I want to convert them to xarray because I need the ‘pr’ to be 2D(with no repeated long or lat) like the following one. Here is …
Calculate 14-day rolling average on data with two hierarchies
I am trying to calculate the 14 day rolling average for retail data with multiple different hierarchies. The ‘Store’ dataframe looks like this: What I am trying to do is create a rolling 14 day average for the purchases column for each store. The data extends well past 14 day (over 8 months), and …
Matplotlib plot barplots-stacked in a loop in different positions on x-axis
I have a list of dictionaries that have different keys and a different number of keys. I want to plot these elements in this list (dictionary), each element as a stacked bar plot. I could plot a single dictionary using the following code. I expected something like this But every bar is plotted in the same loc…