Given the following DataFrame of pandas in Python: Displays the switching on and off of 3 light bulbs at different times using date and time objects. I want to add a new column, called cost_days. This column will include only for rows where the variable using_time is different from NaT. Information on how man…
Tag: dataframe
python_ hh:mm:ss.000 in excel converts to dataframe by xlwings has problem
When I build exe file because of DRM i can’t use pd.read_excel or pd.ExcelFile for open excel files. So I try to use xlwings for open the DRM excel file. But time data converts to something strange data…by xlwings. I don’t know what’s it and how to fix. -here is time data- result : Ans…
I want to add date range where value is True in pandas
Dt 1/2/21 2/2/21 3/2/21 4/2/21 5/2/21 6/2/21 7/2/21 Attendance(Expected output in python) san TRUE TRUE TRUE TRUE TRUE TRUE TRUE 1/2/21 – 7/2/21 don TRUE TRUE FALSE TRUE TRUE TRUE TRUE 1/2/21 -2/2/21,4/2/21-7/2/21 sam FALSE TRUE TRUE FALSE TRUE TRUE TRUE 2/2/21 – 3/2/21,5/2/21-7/2/21 den FALSE FAL…
extract key and values from nested jsons and put in a DataFrame
I have a json object that looks like this: Is it possible to extract all dates (key) along with their respective “revenue” values and put them into a dataframe that looks likethis: Answer How about something like:
panda dataframe extracting values
I have a dataframe called “nums” and am trying to find the value of the column “angle” by specifying the values of other columns like this: When I do so, I do not get a singular number and cannot do calculations on them. What am I doing wrong? nums Answer First of all, in general you s…
Dask Df convert All Dtype using dictionary
Is there an easy equivalent way to convert all columns in a dask df(converted from a pandas df) using a dictionary. I have a dictionary as follows: and would like to convert the pandas|dask df dtypes all at once to the suggested dtypes in the dictionary. Answer Not sure if I understand the question correctly,…
Pandas dataframe: select list items in a column, then transform string on the items
One of the columns I’m importing into my dataframe is structured as a list. I need to pick out certain values from said list, transform the value and add it to one of two new columns in the dataframe. Before: Name Listed_Items Tom [“dr_md_coca_cola”, “dr_od_water”, “potatoe…
Aggregating Pandas DF – Losing Data
I’m trying to aggregate a pandas df in a way an excel pivot table would. I have one quantitative variable called “Count”. I would like the same qualitative variables to combine and the “Count” data to sum. However, when I am trying to do this with the below code, I see that I am …
Parsing a Pandas Dataframe
I have a dataframe like this; Looking like this in Jupyter notebook output; I want to parse this table so that table name repeats with each field name and column counts remain the same such as the output dataframe will look like; I tried this code from a stackoverfow solution; But it did not work. In the solu…
return index of matching value over columns in dataframe
my input: I trying get over df all range where matching value is true. My code: What I get:* [2, 3, 4, 5] So its correct, but how to get all index over each column in df? In other word, I dont want input manually name of column to get index matching value, but get ouptut per column. So what