0

I want to merge some dataframe from csv files using for loop in python. But the result is empty. Why is that so? Here is my code.

result = pandas.DataFrame(columns = ['col_A', 'col_B'])
for i in range(0, 5):
    #col_A is integer for numbering, col_B is float in range 0 to 1
    temp = pandas.DataFrame([[0, 0.5132443], [1, 0.12436421], [2, 0.12341162]], columns = ['col_A', 'col_B'])
    result.merge(temp)
print(result) #result is empty dataframe

1 Answers1

1

You need to store the result of the merge:

result = result.merge(temp)

From the (DOCS

Returns:

merged : DataFrame

The output type will the be same as ‘left’, if it is a subclass of DataFrame.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135