0

I'd like to drop unnecessary rows in a file, but the data types in my raw data is stated as object. I've tried to convert it using the .astype however it did not seem to work.

df = pd.read_csv(raw_data, header=None) 
print(df.dtypes) headers = ['random'] 
print("headers\n", headers) 
df.columns = headers print(df.dtypes)

enter image description here

I only need the data which looks like this:

::rc=80000000:lq=135:ct=31D2

everything else is unnecessary.

EarlGrey
  • 2,514
  • 4
  • 34
  • 63
pradinipus
  • 11
  • 3
  • Does this answer your question? [Python pandas: remove everything after a delimiter in a string](https://stackoverflow.com/questions/40705480/python-pandas-remove-everything-after-a-delimiter-in-a-string) – sdhaus Feb 07 '20 at 15:41

1 Answers1

0

Type object is how Pandas stores strings (until the recently released v1, but still, it's not an issue that the type is object for your purposes). When you say that you want data to look like that row, it depends on how specific you have to be. If it's enough to check for rows that have ::rc= then you could do something like this:

df[df.random.str.contains('::rc=')]

Otherwise, you could use a more elaborate regex pattern to get exactly the rows that you want.

Oriol Mirosa
  • 2,756
  • 1
  • 13
  • 15