Given a df I would like to calculate the time diffrence between the first row and the subsequent rows under the column time and express the result in the unit of seconds. However the compiler return an error The code to reproduce the above error is Expected output Answer You need to change the dtype to ‘…
Tag: pandas
fixing the toolbar i made with tkinter
i created a simple program with Tkinter but i have a small problem i have a graph and i am using .grid() to place it and webar1.get_tk_widget().grid(column=2, row=3, rowspan=20, sticky=”nesw”) the result is: the first result but then when i am aligning it to the left with column 0 like that bar1.g…
Pandas: New column with values greater than 0 and operate with these values
I have a big dataframe with more than 2500 columns but the structure is very similar than this: I need to detect all the columns with a value greater than 0 and I have done with this: And then I get this: The problem is that I don’t need in ‘X’ the name of the columns but the value of
How to handle Pandas columns where elements are Lists?
I have loaded some JSON API data as a Pandas dataframe, as such, there are some columns that come out as lists. I also have some NaN values. First and foremost I want to replace the NaN with a single word such as ’empty’ but the rest of the data are already in list forms. I want to ultimately crea…
change value by key of another dataframe
I think it is very easy and simple question. but it is very difficult for me. please help! I can write R code input df a is a df, it have key and answer value. b is a df, it have to change according to a. final result (what I want) but I don’t know how to write python. I
Join two data frames by searching & matching exactly same strings
I have two python dataframes: one of them have a column has a row ‘AC-2’ another data frame includes columns which has a string row ‘AC-20,AC8,AC-15’ First dataset: second dataset: I found: above there is a matching between AC-2 for dataset1 and AC-20 in string for dataset 2 but they a…
Pandas’ read_html not reading html tables
I am trying to see if I can use, and only use, Pandas’ read_html function to scrape HTML tables from the following website: https://www.baseball-reference.com/teams/ATL/2021.shtml I can fulfil my needs using selenium/bs but want to see if I can scrape this site’s tables with just pd.read_html alon…
How to use exception handling in pandas while using a function
I have the following dataframe: I am attempting to use langdetect to detect the language of the text elements in column y. This is the code I have used for that purpose: Unfortunately, there are non-textual elements (including blanks, symbols, numbers and combinations of these) involved in this column, so I g…
Sorting rows by the number of list elements the row contains
Taking as example the following table: index column_1 column_2 0 bli bli d e 1 bla bla a b c d e 2 ble ble a b c If I give a token_list = [‘c’, ‘e’] I want to order the table by the number of times the tokens each row contains in column number 2. By ordering the table
Clean Data using Pandas
I have the data in this format, and I want to turn it around in an horizontal shape, and in the same time accumulate the count of one product, when the date and hour data are the same. I put below the new desired data frame. Is this feasible using pandas? Or any other python library? Answer You could groupby+…