Hi I am getting this error but everything seems ok.
import matplotlib.pyplot as mpl
import pandas as pd
#Uploading data to Python Pandas Dataframe
db_fondos = pd.read_excel('/Users/jonathanprieto/Documents/GitHub/GoogleMaps/data/- Matriz TDF Python.xlsm',
sheet_name="DB Fondos")
ts_flujos = pd.read_excel('/Users/jonathanprieto/Documents/GitHub/GoogleMaps/data/- Matriz TDF Python.xlsm',
sheet_name="TS Flujos")
ts_ind_fin = pd.read_excel('/Users/jonathanprieto/Documents/GitHub/GoogleMaps/data/- Matriz TDF Python.xlsm',
sheet_name="TS Ind. Fin.")
ts_market = pd.read_excel('/Users/jonathanprieto/Documents/GitHub/GoogleMaps/data/- Matriz TDF Python.xlsm',
sheet_name="TS Market data")
db_posiciones = pd.read_excel('/Users/jonathanprieto/Documents/GitHub/GoogleMaps/data/- Matriz TDF Python.xlsm',
sheet_name="DB Posiciones")
print('Carga completada')
#NaN = np.nan
#db_posiciones["Id. Pos."] = NaN
#db_posiciones.head()
print(db_posiciones)
diccionario=db_fondos.set_index("Fondo")["Id. Fondo"].to_dict()
for index, row in db_posiciones.iterrows():
ipos = row["Fondo"]
print(ipos)
if ipos in diccionario:
idpos=diccionario[ipos]
twofirst=row["Fondo"][:2]
twofirst = twofirst[0:2]
print(idpos+"-"+twofirst)
db_posiciones["Id. Pos."].values[index] = str(idpos)+"-"+str(twofirst)
print(index)
print(db_posiciones)
Could anyone told me why I am getting this error:
File "/Users/jonathanprieto/Documents/GitHub/GoogleMaps/test.py", line 36, in <module>
db_posiciones["Id. Pos."].values[index] = str(idpos) + "-" + str(twofirst)
ValueError: could not convert string to float: '91_AGSACB_08-65'
db_posiciones["Id. Pos."].valuescolumn? Is'91_AGSACB_08-65'that kind of value? Are you surprised that ` str(idpos)+"-"+str(twofirst) ` produces that kind of value? Are you expecting the conversion to happen automatically? If so, what should the value be in this case?91_AGSACB_08-65(hint: what does the error message say it was)?db_posiciones["Id. Pos."].values[index]is the wrong way to try to slice your data. Just dodb_posiciones["Id. Pos."].loc['91_AGSACB_08']or.iloc[]. Please read the pandas Getting Started doc about how to slice properly with.loc[]/.iloc[]asnd string/ integer row-labels.