Python Forum
drop rows that doesnt matched
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
drop rows that doesnt matched
#3
(Oct-26-2019, 11:57 AM)snippsat Wrote: Your csv.file link dos not work.
Can do it like this,it's not type() in pandas but dtypes.
>>> import pandas as pd

>>> df = pd.DataFrame({"x": ["a", "b", "c"], "y": [1, 2, 3], "z": ["d", "e", "f"]})

>>> df
   x  y  z
0  a  1  d
1  b  2  e
2  c  3  f

>>> df.dtypes
x    object
y     int64
z    object
dtype: object

>>> df = df.select_dtypes(exclude=['object'])
>>> df
   y
0  1
1  2
2  3
An other approach is to convert to correct types if that's needed.
>>> df = pd.DataFrame({"x": ["4", "5", "6"], "y": [1, 2, 3], "z": ["d", "e", "f"]})

>>> df
   x  y  z
0  4  1  d
1  5  2  e
2  6  3  f

>>> df.dtypes
x    object
y     int64
z    object
dtype: object

>>> df['x'] = df['x'].astype('int')
>>> df.dtypes
x     int32 # Now integer
y     int64
z    object
dtype: object

Hi Thks for replying. I want to drop rows not columns ... hier ist the file file.csv

I want to drop rows that doesnt start/look like a date (although the dtypes is still an object and not dateimt64[ns])
Thks
Karlito
Reply


Messages In This Thread
drop rows that doesnt matched - by karlito - Oct-25-2019, 05:58 PM
RE: drop rows that doesnt matched - by snippsat - Oct-26-2019, 11:57 AM
RE: drop rows that doesnt matched - by karlito - Oct-26-2019, 02:14 PM
RE: drop rows that doesnt matched - by snippsat - Oct-26-2019, 04:51 PM
RE: drop rows that doesnt matched - by karlito - Oct-28-2019, 10:19 AM
RE: drop rows that doesnt matched - by snippsat - Oct-28-2019, 10:55 AM
RE: drop rows that doesnt matched - by karlito - Oct-28-2019, 12:21 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Drop rows if a set of columns has a value dervast 1 2,016 Sep-12-2019, 04:18 PM
Last Post: sd_0912
  Drop rows from data with zero value Devilish 3 3,779 Dec-27-2018, 02:06 AM
Last Post: Devilish

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020