python - How to ignore very first value in a CSV file? -
i have csv file (node.csv) following data:
0 1 2 3 4 0 12.0 12.5 11.0 10.0 nan 1 15.0 18.0 nan 15.0 17.0 2 20.0 nan 20.0 28.0 27.0 #####this output following format of data: sensor_values = {0: {0: 12.0, 1: 15.0, 2: 20.0}, 1: {0: 12.5, 1: 18.0, 2: np.nan}, 2: {0: 11.0, 1: np.nan, 2: 20.0}, 3: {0: 10.0, 1: 150.0, 2: 28.0}, 4: {0: np.nan, 1: 15.0, 2: 27.0} }
of course, above data clearer picture. actual data in file following:
,0,1,2,3,4 0,12.0,12.5,11.0,10.0,np.nan 1,15.0,18.0,np.nan,15.0,17.0 2,20.0,np.nan,20.0,28.0,27.0
there absolutely no problem when try print data in file using pandas dataframe output looks 1 wrote above. problem arises when try load data list using following code:
import pandas pd #some other code sensor_values = pd.read_csv('node.csv') #or using instead of read_csv - #sensor_values = pd.dataframe.from_csv('node.csv') sensor_values = sensor_values.values.tolist()
it takes in blank data in first row first column (" ",.....) of csv data file, not want in script. want relevant data taken, seems start taking data blank value.
how prevent this?
there modification need in csv file data itself?
in advance :)
although credit goes @jezrael documentation looking found here: https://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html
import pandas pd import io data = """,0,1,2,3,4 0,12.0,12.5,11.0,10.0,np.nan 1,15.0,18.0,np.nan,15.0,17.0 2,20.0,np.nan,20.0,28.0,27.0 """ df = pd.read_csv(io.stringio(data),index_col=0) df.to_dict()
output
{'0': {0: 12.0, 1: 15.0, 2: 20.0}, '1': {0: '12.5', 1: '18.0', 2: 'np.nan'}, '2': {0: '11.0', 1: 'np.nan', 2: '20.0'}, '3': {0: 10.0, 1: 15.0, 2: 28.0}, '4': {0: 'np.nan', 1: '17.0', 2: '27.0'}}
Comments
Post a Comment