jeudi 23 septembre 2021

problem with replacing specific values of a file based on lat,lon values in pandas

I have an ascii file containing values for different lon,lat points. I want to set the values to zero for specific lat,lon points. I do the following:

import pandas as pd

col_names=['ID', 'Lon','Lat','H1','H2','H3','H4','H5','H6','H7','H8','H9','H10','H11','H12','H13','H14','H15','H16','H17','H18','H19','H20','H21','H22','H23','H24']
        df = pd.read_csv(i,sep='\s+',names=col_names,header=None) 

        if (df['Lon']==22.8500003815 & df['Lat']==40.625) |df['Lon']==22.8500003815 & df['Lat']==40.6749992371):
            for jj in range(1,24,1):
                df['H'+str(jj)] = 0

        df.to_csv(outfile,sep='\t',header=False)

but I get the TypeError: Cannot perform 'rand_' with a dtyped [float64] array and scalar of type [bool]

Aucun commentaire:

Enregistrer un commentaire