pandas

Is .diff(period=-10) working on pandas series?

Is .diff(period=-10) working on pandas series? Question: I have a dataframe like so: import pandas as pd import numpy as np date_rng = pd.date_range(start="2023-11-18", periods=3, freq="10S") values = [4, 2, 3] df = pd.DataFrame(data={"values": values}, index=date_rng) df["dt"] = df.index.to_series().diff().dt.seconds df["dt"] = df.index.to_series().diff(periods=2).dt.seconds df["dt_neg"] = df.index.to_series().diff(periods=-1).dt.seconds print(df) gives values dt dt_neg 2023-11-18 00:00:00 4 NaN 86390.0 …

Total answers: 1

How can i read csv from zip file python?

How can i read csv from zip file python? Question: I am trying to read csv which is in zip file. My task is to read the file rad_15min.csv file but the issue is when i read zip file (I copied link address by clicking on download button) it gives me error: Code: import pandas …

Total answers: 2

Finding the longest streak of numbers, sum the values of that group and create an new dataframe

Finding the longest streak of numbers, sum the values of that group and create an new dataframe Question: This is an extension to this post. My dataframe is: import pandas as pd df = pd.DataFrame( { ‘a’: [ ‘a’, ‘a’, ‘a’, ‘a’, ‘a’, ‘a’, ‘a’, ‘a’, ‘a’, ‘a’, ‘a’, ‘a’, ‘b’, ‘b’, ‘b’, ‘b’, ‘b’, …

Total answers: 2

Select top n groups in pandas dataframe

Select top n groups in pandas dataframe Question: I have the following dataframe: Country Crop Harvest Year Area (ha) Afghanistan Maize 2019 94910 Afghanistan Maize 2020 140498 Afghanistan Maize 2021 92144 Afghanistan Winter Wheat 2019 2334000 Afghanistan Winter Wheat 2020 2668000 Afghanistan Winter Wheat 2021 1833357 Argentina Maize 2019 7232761 Argentina Maize 2020 7730506 Argentina …

Total answers: 2

load jsonl File with OpenAI API request results to pandas data.frame

load jsonl File with OpenAI API request results to pandas data.frame Question: I have a large data set containing around 500k observation. It has a string variable that I want to create an embedding for. I used the OpenAI API to create the embedding and because of the large number of observations I used their …

Total answers: 1

Searching for values in large dataframe with unnamed columns

Searching for values in large dataframe with unnamed columns Question: I have a dataframe with ~300 columns in the following format: | Column1 | Column2 | Column3 | Column5 | ————| ————– |———–|———- | Color=Blue | Location=USA | Name=Steve| N/A | Location=USA| ID=123 | Name=Randy| Color=Purple | ID=987 | Name=Gary | Color=Red | Location=Italy What …

Total answers: 3

plot multiple lists

plot multiple lists Question: I am Building a GUI by Python and want to plot the the daily bonus of employees depends on the user plotting target: Bob=[100,30,50,90] Sammy=[10,60,90,200] Tom=[70,90,90,90] # input from GUI User is Tom ploting_target=’Tom’ if ploting_target==’Tom’:` plt.plot([0,1,2,3], Tom) elif ploting_target==’Sammy’: plt.plot([0,1,2,3], Sammy) plt.plot([0,1,2,3], Tom) ____________________________________________ #expecting #find_target=list_of_employee.index(ploting_target) #plt(plot([0,1,2,3], list_of_employee[find_target]) Asked By: …

Total answers: 1

Python pandas rolling sum positive number with duplicate timestamps

Python pandas rolling sum positive number with duplicate timestamps Question: have a dataframe with two columns like below. One column is datetime and another is purely numbers. I’d like to sum all positive numbers of last 5 minutes.Tried df[‘positive’] = df[‘number’].rolling(‘5T’).sum() but didn’t work. Somehow, getting a ValueError: window must be an integer 0 or …

Total answers: 2

Duplicate pairs of rows side by side in pandas given certain condition

Duplicate pairs of rows side by side in pandas given certain condition Question: I have the following code: import pandas as pd data = { ‘Col1’: [‘John 1’, ‘John 2’, ‘John 3’, ‘Kyle 1’, ‘Kyle 3’, ‘Kyle 2’], ‘Col2’: [‘B’, ‘C’, ‘E’, ‘F’, ‘F’, ‘S’], ‘Col3’: [‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘2’] } df = …

Total answers: 4