'Pandas Dataframe return rows where state, city, and date occur multiple times
Firstly, this is my first post, so my apologies if it is formatted poorly.
So I have this dataframe which I have attached a picture of. It contains UFO sightings and I want to return the rows where the if the city and state are the same and then also if the dates are the same. I am trying to find sightings that occurred on the same day in the same city and state. Please let me know if more info is required. Thank you in advance!
Solution 1:[1]
Alternative, boolean indexing to keep the duplicated rows:
df['date'] = pd.to_datetime(df['occurred_date_time']).dt.normalize()
df2 = df[df.duplicated(['date','city','state'], keep=False)]
If you don't want the new column:
df2 = df[df.assign(date=pd.to_datetime(df['occurred_date_time'])
.dt.normalize())
.duplicated(['date','city','state'], keep=False)]
Solution 2:[2]
Try this.
# Create a column converting date_time to just date
df['date'] = pd.to_datetime(df['occurred_date_time']).dt.normalize()
# groupby and count times where date, city and state
# then create boolean series where count is greater than 1
m = df.groupby(['date','city','state']).transform("count") > 1
# boolean filter the dataframe rows with that series, m.
df[m]
Solution 3:[3]
No you can't & It's not advisable to run these kind of scripts in you cmd/Powershell....
Solution 4:[4]
You can't format a PC, but you can format a disk using format command. And for backup you can copy files to a folder or a disk using xcopy.
Solution 5:[5]
You should first create and run one script, before the process start, 'cause u could potencially overlap the time that the OS need to prepare the process, that saves you work, files, statuses... etc
Write another one that it's able to read and execute this one.
Then you can upload them (or write the process to autoupload it in the script) to save both in any cloud based solution.
Finally, when the PC is restored, you just need to download it one from the cloud, and it should be able to download the another one and run it, restablishing your previous status.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | mozway |
| Solution 2 | |
| Solution 3 | Bhargav |
| Solution 4 | SuperPuiu |
| Solution 5 | Pyzyryab |

