New Python user here, so I appreciate any ideas for best practices in addition to the issue I’m seeking advice on. I have code that works for a small number of records, but when I run it on a large dataframe, it takes too long. I’ve done a lot of reading on this issue, and there are several similar posts
Tag: dataframe
Select Rows Based on Time Difference [Before or After] In Columns
I have the following dataset of students taking 2 different exams: I want to select those students whose two exams are 10 days apart from each other in either direction. I am trying Timedelta, but I’m not sure if it’s optimal. Desired Output: Is there any better way of getting the desired output? Any suggestions would be appreciated. Thanks! Answer
multiple for in python query loop and save them
need to save them into different data frames the expected result is running these batches for each class individually. e.g df_class1, df_class2 df_class3, df_class4 each results as sth like ;df_class1, df_class2 df_class3, df_class4 Answer You can use formatted string to save the resultant dataframe for each iteration.
Pandas DataFrame: How do I create numerical values out of numerical values from another column?
I have probably not explained my issue right in the headline, so let’s try to clarify it here. I want to categorise values from 1 column into a new one. The first ten lines in my data set are this: And the code I use is this I think this can be done easier with a user-defined function, but I
Create a DataFrame from list in lists (Pandas)
I´m having trouble creating a dataframe on my list. The list contains four columns, but instead it says on presente one column with data: The list itself is presented in this way: I know there is something happening due to the double [], but i can´t figure it out. Can´t someone help me? Here is the code so far: Answer
How can I write a Python function that loops through a list of dataframes and drops duplicate rows?
I have a “Main” dataframe which is being continuously built. Each month I merge new data into that one, however I want to remove rows that exist in both dataframes. Example “Main” Name Date Begin Time End Time Bob 03/10/2022 11:04 14:10 Dirk 05/12/2022 13:15 16:56 Steve 01/13/2022 11:11 13:13 “Other” Name Date Begin Time End Time Rog 03/14/2022 11:44
Create new column with conditions in Pandas
I have two dataframes which are: The first dataframe could be created with the Python code: and the second dataframe: I want to create a second column in the first dataframe and the value of each Date in the new column will be the value of the first Date in the second dataframe equal to or earlier than the Date
How to do left join with larger table, keeping left tables size?
I have a dataframe1: and dataframe2: i want to join type column to dataframe1 by id to get: How could I do that? as you see output table is same shape as dataframe1? but when i use pd.merge output is larger Answer Try this: Output:
count list values that appears in dataFrame using python
I want to count list value that is exists in dataframe: I want to use a loop to go through list values and dataframe df and if list[0] exist in df count++. my code: df = pd.read_excel(‘C:UsersmaDesktopfilee’) df looks like this : Intents Examples First something Second something listX= [“HOFF”, “Customers”, “bank”] I did this but not working: Answer Firstly,
How to change y-axis limits on a bar graph?
I have a df, from which Ive indexed europe_n and Ive plotted a bar plot. europe_n (r=5, c=45), looks like this. ; df[‘Country’](string) & df[‘Population’](numeric) variable/s. Which gives me; Objective: Im trying to change my y-axis limit to start from 0, instead of 43,094. I ran the, plt.ylim(0,500000) method, but there was no change to the y-axis and threw an