1

I have the following dataframe:

           MATERIAL KW_WERT NETTO_EURO                 TA  
0           S    0.15       18.9                   D  
1            S   0.145      18.27                  D  
2            S   0.145      18.27                  D  
7            S   3.011     252.92                 AN  
8            S   3.412     429.91                 AN  
9            S     0.9      113.4                 AN  
14           S   0.007         KW             N  
15          S     0.3      46.05          SONSTIGES  

how can I filter for the datatype (string) in the column NETTO_EURO an delete it?

The point is that the basic data I get includes some errors and I cant sum up the columns with a string data in it. Now is the first solution to delete the row. Later I will try to fix it otherwise.

1 Answer 1

1

You can use mask with to_numeric and notnull with boolean indexing:

print (pd.to_numeric(df.NETTO_EURO, errors='coerce').notnull())
0      True
1      True
2      True
3      True
4      True
5      True
6      True
7      True
8      True
9      True
10     True
11     True
12     True
13    False
14    False
15     True
Name: NETTO_EURO, dtype: bool

print (df[pd.to_numeric(df.NETTO_EURO, errors='coerce').notnull()])
   MATERIAL  KW_WERT NETTO_EURO          TA
0    S    0.150       18.9         H
1    S    0.145      18.27         H
2    S    0.145      18.27         H
3    S    0.150       18.9         H
4    S    0.150       18.9         H
5    S    0.145      18.27         H
6    S    0.150       18.9         H
7    S    3.011     252.92  AN
8    S    3.412     429.91  AN
9    S    0.900      113.4  AN
10   S    0.281       23.6  AN
11   S    0.078       9.83  AN
12   S    0.107      13.48  AN
15  S    0.300      46.05   SONSTIGES

If has old version of pandas use convert_objects:

print (df[df["NETTO_EURO"].convert_objects(convert_numeric=True).notnull()])
   MATERIAL  KW_WERT NETTO_EURO          TA
0    S    0.150       18.9         H
1    S    0.145      18.27         H
2    S    0.145      18.27         H
3    S    0.150       18.9         H
4    S    0.150       18.9         H
5    S    0.145      18.27         H
6    S    0.150       18.9         H
7    S    3.011     252.92  AN
8    S    3.412     429.91  AN
9    S    0.900      113.4  AN
10   S    0.281       23.6  AN
11   S    0.078       9.83  AN
12   S    0.107      13.48  AN
15  S    0.300      46.05   SONSTIGES
Sign up to request clarification or add additional context in comments.

5 Comments

thanks for your answer.. but i get and "invalid string" at this point errors='coerce' because of the =
There is problem with old version of pandas. What is your version? print (pd.show_versions())
i got pandas 0.16.2
I think there is problem. Can you upgrade to last version of pandas, 0.18.1?
unfortunately not... im working on a company computer! Therefore i cant install anything.. i have to use what is given...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.