Using pandas, index error - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: Using pandas, index error (/thread-11927.html) |
Using pandas, index error - fyec - Aug-01-2018 I am trying to round numbers, if their decimal numbers end with (125, 375, 625, 875), I replace them with (25, 25, 75, 75). My code is: import pandas as pd inpExcelFile = 'Lat Lon Coordinates and soil.csv' #lat, lon gridCells = pd.read_csv(inpExcelFile) #inpExcelFile can be downloaded from "http://www.evernote.com/l/AWMD9Le15ytJmokhnUF8r84vtXVIsj2_lBQ/" df = pd.DataFrame(columns=['lat_ext', 'lon_ext', 'lat_close', 'lon_close']) for i in range(0, len(gridCells.index)): if str(df.at[i, 'lat_ext'])== str('125'): df.at[i, 'lat_close'] = float((str(gridCells.at[i, 'lat'])[:3]) + str('25')) if str(df.at[i, 'lat_ext'])== str('375'): df.at[i, 'lat_close'] = float((str(gridCells.at[i, 'lat'])[:3]) + str('25')) if str(df.at[i, 'lat_ext'])== str('625'): df.at[i, 'lat_close'] = float((str(gridCells.at[i, 'lat'])[:3]) + str('75')) if str(df.at[i, 'lat_ext'])== str('875'): df.at[i, 'lat_close'] = float((str(gridCells.at[i, 'lat'])[:3]) + str('75')) for j in range(0, len(gridCells.index)): if str(df.at[j, 'lon_ext'])== str('125'): df.at[j, 'lon_close'] = float((str(gridCells.at[j, 'lat'])[:3]) + str('25')) if str(df.at[j, 'lon_ext'])== str('375'): df.at[j, 'lon_close'] = float((str(gridCells.at[j, 'lat'])[:3]) + str('25')) if str(df.at[j, 'lon_ext'])== str('625'): df.at[j, 'lon_close'] = float((str(gridCells.at[j, 'lat'])[:3]) + str('75')) if str(df.at[j, 'lon_ext'])== str('875'): df.at[j, 'lon_close'] = float((str(gridCells.at[j, 'lat'])[:3]) + str('75')) df.to_excel('cikti' + '.xlsx')I am getting this error: How can I solve that problem?
RE: Using pandas, index error - volcano63 - Aug-01-2018 Disregarding the fact that this is misuse of pandas API, your df is empty - so applying df.at cannot yield any result
|