I have a pandas dataframe that I want to group by and create columns for each value of col1 and they should contain the value of col2. And example dataframe: I want to groupby item_id, create as many columns as feature_category_id and fill them with the feature_value_id. The resultant df for the example would…
Tag: python
Compare values within a certain timeframe in arrays
I am trying to compare values (0’s and 1’s) in a array. I want to search for each “1” that appears in one column, for another “1” in the other column in a specific timeframe (for example, 5 seconds, 10 seconds, etc.). I will call the 1’s as “signals”. In e…
RuntimeError: Given groups=1, weight of size [32, 16, 5, 5], expected input[16, 3, 448, 448] to have 16 channels, but got 3 channels instead
I am getting the following error and can’t figure out why. I printed the input size of my torch before it gets fed to the CNN: Here is my error message: I defined a CNN with 5 convolutional layers and two fully connected layers. I am feeding in batches of 16 and have resized the images to be (448×4…
Capture first image from h.264 video streaming using websocket – Python
I’m trying to capture a single image from H.264 video streaming in my Raspberry Pi. The streaming is using raspivid with websocket. But, cannot show a correct image in imshow(). I also tried to set the .reshape(), but got ValueError: cannot reshape array of size 3607 into shape (480,640,3) In client sid…
Pandas Dataframe into nested Dictionaries conversion in Python
I need a little help. I want to convert from dataframe into nested dictionaries. and i want to convert in this format: Answer We can do groupby with agg dict items
How to get strftime to output yearly quarters?
I am trying to create a list of year-quarters in python; per the documentation (https://pandas.pydata.org/docs/reference/api/pandas.Period.strftime.html), %q (I believe) should output an integer representation of calendar quarter, but instead the output I get is just %q literally. Input: Expected Output: Actu…
How to convert timezone in number to UTC?
I have some random dates with different timezones, they are in formats like this “07 Mar 2022 13:52:00 -0300”, or they could be like this: “07 Mar 2022 11:12:00 -0700”. I don’t know which timezone exactly they will be coming from. How can I convert all of them to UTC time “…
Retrieve n-grams with word2vec
I have a list of texts. I turn each text into a token list. For example if one of the texts is ‘I am studying word2vec’ the respective token list will be (assuming I consider n-grams with n = 1, 2, 3) [‘I’, ‘am’, ‘studying ‘, ‘word2vec, ‘I am’,…
How to convert real coordinates to a 0-1 grid?
I have a set of coordinates like this: I would like to convert them to 0-1 matrix that would represent a tiles of 100×100 size where 1 is when the point (array row) is within a particular tile. How can I quickly do this? Answer I’m confused about the question — do you want a grid that is 0 ev…
export a comma-separated string as a text file without auto-formatting it as a CSV
Im developing an API which should, ideally, export a conmma-separated list as a .txt file which should look like alphanumeric1, alphanumeric2, alphanumeric3 the data to be exported is coming from a column of a pandas dataframe, so I guess I get it, but all my attempts to get it as a single-line string literal…