Skip to content

Tag: pandas

Update column based on other column condition

I need to update vid or maybe create a new column based on the change column df = [{‘vid’: 14, ‘change’: 0}, {‘vid’: 15, ‘change’: 1}, {‘vid’: 16, ‘change’: 0}, {‘vid’: 16, ‘change’: 0}, {‘vid’: 17, &#8…

Pandas: Remove Column Based on Threshold Criteria

I have to solve this problem: Objective: Drops columns most of whose rows missing Inputs: 1. Dataframe df: Pandas dataframe 2. threshold: Determines which columns will be dropped. If threshold is .9, the columns with 90% missing value will be dropped Outputs: 1. Dataframe df with dropped columns (if no column…

Remove timezone (+01:00) from DateTime

I would like to delete the timezone from my dateTime object. Currently i have: 2019-02-21 15:31:37+01:00 Expected output: 2019-02-21 15:31:37 The code I have converts it to: 2019-02-21 14:31:37. Answer In the first line, the parameter utc=True is not necessary as it converts the input to UTC (subtracting one …

Pandas – Duplicate Rows and Slice String

I’m trying to create duplicate rows during a dataframe on conditions. For example, I have this Dataframe. And I would like to get the following output: Answer For pandas 0.25+ is possible use DataFrame.explode with splitted values by Series.str.split and for remark column list comprehension with filteri…