Data Frame: I want the data frame which consists for only year with 2020 and 2021 using search and match methods. Answer
Tag: pandas
Python: Round decimal places after seconds in timestamp
I have this series: Initially, I wanted to round to seconds by doing: However, I am trying to merge this dataset to another of higher frequency. So I’d like to round the decimal places of the timestamp instead. Example: 2021-06-15 16:23:04.388 would become 2021-06-15 16:23:04.380 How can I do this? to a…
Check if values in one dataframe match values from another, updating dataframe
Let’s say I have 2 dataframes, both have different lengths but the same amount of columns Lets assume that some of the data in df1 is outdated and I’ve received a new dataframe that contains some new data but not which may or may not exist already in the outdated dataframe. I want to find out if a…
How can I split a cell in a pandas dataframe and keep the delimiter in another column?
persons John New York Janet New York Mike Denver Michelle Texas I want to split into 2 columns: person and city. I tried this: and it gives me this: What I want is to split by cities and keep the separator in the city column like this: Answer You can use regex with a capture group: Read more on how
Pandas fill missing dates and values simultaneously for each group
I have a dataframe (mydf) with dates for each group in monthly frequency like below: I want to fill the dt for each group till the Maximum date within the date column starting from the date of Id while simultaneously filling in 0 for the Sales column. So each group starts at their own start date but ends at t…
DataFrame comparison with SQL Server table and upload just the differences
I have an SQL table (table_1) that contains data, and I have a Python script that reads a csf and creates a dataframe. I want to compare the dataframe with the SQL table data and then insert the missing data from the dataframe into the SQL table. I went around and read this comparing pandas dataframe with sql…
Pandas create flag if any condition fails
I have a huge pandas dataframe (actually has 5M rows): My requirement is to create a flag with value as 1 if any of the close dates cls1..5 is < the corresponding open date opn1..5 Example output: for id==2, cls5 < opn5 I want to avoid a loop and run it as fast as possible. There are ~5M rows in
PyQt5 QDoubleValidator don’t allow to write dot separators : x.y
Hello everyone, I’m trying to develop a GUI to modify and make computation on Pandas DataFrames with the PyQt5 module. I could actually display my DataFrame, and Edit specific column or not. It’s displayed in a QTableWidget. I tried to implement a QItemDelagate with the QDoubleValidator to write o…
Can I get the value of a index if there seems to be multiple indexes? [duplicate]
This question already has answers here: Pandas – extracting month and year from index (3 answers) Closed 7 months ago. I have this df: I had to pivot this table so I think ticker & date are indexes(?) df.columns results in: I wanted to create a new column for the year(I belive this does the trick &#…
Pandas pivot value are merged
Hi have data like below result like below I want the sum of qty value Answer Based on the output, it seems to me that “qty” a “string” dtype. Try forcing it to be a “float” and try again: