Suppose I have a dataframe: Case_no Event_ID Date Type Done_by 1 1 2023-01-01 Email Sent Customer 1 2 2023-01-02 Response Agent 1 3 2023-01-03 Email Sent Customer 1 4 2023-01-10 Response Agent 2 5 2023-01-02 Email Sent Customer 2 6 2023-01-04 Email Sent Customer And I wanted to add two boolean columns that check for each case if an email
Tag: pandas
Concatenating CSVs into dataframe with filename column
I am trying to concat multiple CSVs that live in subfolders of my parent directory into a data frame, while also adding a new filename column. I can do something like this to concat all the CSVs into a single data frame But is there a way to also add the filename of each file as a column to the
Join two columns of sequentially values
I have dataframe, where ‘A’ 1 – client, B – admin I need to merge messages in row with 1 sequentially and merge lines 2 – admin response sequentially across the dataframe. I do not know how to do this Answer Create groups by consecutive values in B – trick compare shifted values with cumulative sum and aggregate first and
keep the same name until value = true in another pandas column
I have a dataframe with 3 columns: session_id, name, reset_flag. I need to make a new column, new_name, where the new name will be set to the first name where reset_flag=True, and then it will continue as that name WITHIN that session, until there is new reset_flag. Not really sure best way to approach. EDIT: I thought of a way
Compare two lists and write for each item corresponding X column value
Let’s say I have a list of users then I have a table What I want is: to have a list of Date for each Resource A, B, C So desired output could be a dictionary: Answer You can use explode then use groupby and agg(list) at the end get the result as dict with to_dict. Output:
Pandas multindex on column after merge
I created this dataframe: but I need to change order in column multiindex. I need to have something like this Could you help me :) ? Answer You can use swaplevel on the resulting dataframe: Output:
WebScraping: Pandas to_excel Not Displaying full DataFrame
I am brand new to coding, and was given a web scraping tutorial (found here) to help build my skills as I learn. I’ve already had to make several adjustments to the code in this tutorial, but I digress. I’m scraping off of http://books.toscrape.com/ and, when I try to export a Dataframe of just the book categories into Excel, I
How do I create a seaborn lineplot with multiple lines showing the distribution of values per category?
I have a dataframe of cars from 5 different brands with all models and their technical data. Simplified it looks like that: Brand Model Power in HP VW Golf 7 150 Audi A4 190 Audi A5 190 VW Passat 240 VW Polo 80 Ford A4 190 KIA A4 190 Audi Q3 150 Audi S6 400 VW Golf 6 140 VW
Write Dataframe outputs from a for loop to Excel without overwriting Pandas
I have an extensive set of code that results in 6 DataFrames per for-loop run. The column names are tailored to what vehicle I have running through the loops so the column names are different but the sizes of the dataframes are the same. I want to print a couple dataframes to the same sheet but I have issues with
How to convert a dataframe to nested json
I have this DataFrame: All the dataframe fields are ASCII strings and is the output from a SQL query (pd.read_sql_query) so the line to create the dataframe above may not be quite right. And I wish the final JSON output to be in the form I realize that may not be ‘normal’ JSON but that is the format expected by