0

I am trying to change all negative values to 0 in excel files.

However, it seems like the pandas skips the first row.

Please help me with preventing skip issue! Thank you.

Here is the code:

# importing pandas module
import pandas as pd
import numpy as np
import csv
from pandas import DataFrame

df = pd.read_csv("FAPI-N2-rere_2D_modified.csv")

df[df < 0 ] = 0

df.to_csv('FAPI-N2-rere_2D_modified2.csv')

==========================================================

I have tried to add some codes into the above,

# importing pandas module
import pandas as pd
import numpy as np
import csv
from pandas import DataFrame

df = pd.read_csv("FAPI-N2-rere_2D_modified.csv", **header = None**)

df[df < 0 ] = 0

df.to_csv('FAPI-N2-rere_2D_modified2.csv')

However, i keep getting the typeerror:

TypeError: '<' not supported between instances of 'str' and 'int'

I would be so much appreciated if anyone could please help me.

Thank you so much!

griffins
  • 7,079
  • 4
  • 29
  • 54
K P
  • 11
  • 2

1 Answers1

0

Some columns of your dataframe contains strings. If their content is numeric you can try to convert them into numeric datatype, here it is explained how to do that: Change column type in pandas

If you have columns containing strings, you need to replace your negative values only on numeric columns.

esimo
  • 61
  • 2