Answer the question
In order to leave comments, you need to log in
How to add a column with data from a list in pandas?
Hello.
There are two files:
1/ input_csv_file, which has a column ['index']
2/ input_file_w_address, which is a list of tuples: [(index1, address1), (index2, address2)], i.e. at [0] place is index, at [-1] -
address
text_input = open(input_file_w_address, 'r').read()
text_input = eval(text_input)
csv_input = pd.read_csv(input_csv_file)
for i in csv_input['index']:
for i in range(csv_input.shape[0]):
for y in text_input:
text_input_index = y[0]
text_input_address = y[-1]
if i == text_input_index:
csv_input['new_address'] = text_input_address
Answer the question
In order to leave comments, you need to log in
everything turned out to be much simpler:
for y in text_input:
text_input_index = y[0]
text_input_address = y[-1]
csv_input.loc[csv_input['index'] == int(text_input_index),
'new_address'] = text_input_address
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question