I'm trying to fill in value for a specific cell in a dataframe that already has some info in it. When I test it with small data it works but in my project it throws "ValueError : cannot convert string to float"
# df : a dataframe with data to be extracted and added to another dataframe data
some_list = df.iloc[:, 0].values
values = df.iloc[:, 1].values
indexList = data.index.values.tolist()
index = 0
for x in some_list:
s = values[index]
if x in indexList:
# this line raised ValueError : cannot convert __(values in s)__ from string to float
data.at[x, 'Some Column'] = s
index += 1
elements in some_list and values are strings. Here the existing dataframe is data, where one of the column is 'Some Column', and index labels are some elements in some_list (therefore if the current element x in some_list is one of the index label, set value at the cell (row : index label x, column : 'Some Column' ) to values[the same row that this x is found]
before filling in cells under 'Some Column' should be NaN
A small sample I tried testing the .at function with (that didn't raised valueError):
column=['Year', 'first', 'second', 'third']
s = 'label1'
data = pd.DataFrame(columns=column)
row = pd.Series({'Year' : 2019, 'first' : 'asa', 'second' : 'awdqw'}, name=s)
data = data.append(row)
# Creates a pandas DataFrame.
data_snip = {'name':['A', 'B', 'C', 'D'], 'y':[1, 2, 3, 4]}
df = pd.DataFrame(data_snip, index =['one', 'two', 'three', 'four'])
df_array = df.iloc[:, 0].values
s = df_array[3] # should be 'D'
s = 'label3'
row = pd.Series({'Year' : 2030, 'first' : 'ubeubf', 'second' : 'qov.z'}, name=s)
data = data.append(row)
data.at['label3', 'third'] = s
and this is what data looks like :
Year first second third
label1 2019 asa awdqw NaN
label3 2030 ubeubf qov.z D
Any help would be greatly appreciated !!