Skip to content

Tag: pandas

Explode a column with multiple values separated by comma

How are you? I have a database where some lines have more than one product and they are separated by a comma, as in the example below (there are other columns, but to make it more practical I only took these three). id produdct value 47 product1, product 2 12000.0 48 product3 48000.0 49 product4, product1, pr…

How to resample a dataframe an include start and end times?

So I am working with tick data and I am attempting to resample the dataframe to minute bars, but when resample is called the time series begins and ends the first instance that a tick exists. How would I resample this data such that the first and last times can be specified to a certain start and end time? Ed…

Add trend line to datetime matplotlib line graph

I have a pandas dataframe df: And I can plot this easily using plt.plot: But now I want to add a trendline. I tried using some answers: How can I draw scatter trend line on matplot? Python-Pandas Which doesn’t work: Then I found the following question and answer: TypeError: ufunc subtract cannot use ope…

How to adjust row height with pandas Styler

I have a styled pandas DataFrame that I want to export to HTML with smaller rows than default. I don’t know much about CSS so I haven’t found a way to make it work so far. Can it be achieved and if so, how? Answer Set the styles for row and data cell line height and reset the padding

Count number of matches in pairs of pandas dataframe rows

I have been trying to count the number of times different values in a row of dataframe matches with column-wise values in other rows and provide an output. To illustrate, I have a dataframe (df_testing) as follows: I am looking to count the number of exact matches among rows for values in Col_1 to Col_4. For …

Pandas grouping by week

I have a data frame in pandas like this: I need to get the count of items by week. Example: From 9/6 to 9/13, the output should be: Similarly, I need to find the count on these intervals: 9/13 to 9/20, 9/20 to 9/27, and 9/27 to 10/4. Thank you! Answer May be with the caveat of the definition of