Skip to content

Tag: python

Manipulating DataFrame

I have the following dataframe df where there are 3 columns: Date, value and topic. I want to create a new dataframe df1 where the topic is the column and is indexed by day, and each topic has its own value per day. My problem is that I don’t know how to match the value to the topic per day.

unable to set line to input

I am trying to read humidity and temperature values from the AM2301(DHT21). for that I am using the adafruit_dht library which is written for DHT11 & DHT22. because I can’t find any adafruit library for AM2301 so I use this. when I first run the code using some gpio say D17. it works fine and gives …

List of dictionaries, remove dicts with some duplicate key, values

Removing duplicates from list of dicts is as simple as set(list) but i have got stuck with this specific task. I need to filter a list of dicts only by some keys and keep only the first elements I need to get this very result (keep only first elements with same ‘dep_code’ and ‘arr_code&#8217…

Writing a List of Dictionaries to seperate JSONs

I do have dictionary, with each value as a list. I want to write individual items to separate JSON files. For example Now I want 3 jsons i.e data1.jsob, data2.json, data3.json in the following(approx) format. data1.json data2.json and so on. My current approach is But this is wrong. Any helps appreciated. Ans…

Is there a faster way to know if it’s a real triangle?

The following code is intended to return 0 if it’s not possible to form a triangle with three given sides and return 1 if it is possible. Taking into account that it’s not possible for a triangle to have an area of zero or less, first I calculated the semiperimeter of this hypothetical triangle an…

How could the energy and cos function be in different shapes?

I am trying to write a code that calculates an integral from zero to pi. But it gives an error which I do not understand how to fix. Thank you for your time. Answer As is pointed out in the top comment: Energy.shape == (2980,), but x.shape == (1000,) so reduce the number of elements in Energy or increase np.c…