1

I need help...I'm trying to merge tables from different sites.

I succeeded to extract each tables what I want, but I can't merge them into one.. I used 'for~~in' but failed.

[my goal] This image is what I'm trying to make. I'm really new to coding and this community, sorry if the question seems bad.

Thanks for reading Sincerely, KB

import pandas as pd 

ticker = '005930' #'139480'
table = pd.read_html('http://comp.fnguide.com/SVO2/ASP/SVD_Main.asp?pGB=1&gicode=A'+str(ticker)+'&cID=&MenuYn=Y&ReportGB=&NewMenuID=Y&stkGb=701')

report1 = table[10]
report2 = report1.loc[[0, 1, 3, 17]]
report2

#for tickers in ticker:
#    url=print('http://comp.fnguide.com/SVO2/ASP/SVD_Main.asp?pGB=1&gicode=A'+str(ticker)+'&cID=&MenuYn=Y&ReportGB=&NewMenuID=Y&stkGb=701')
Dawn
  • 13
  • 3
  • if the index is the same, you can do a merge. You don't need to do a for loop. Using loops in pandas is a bad thing. There are much better ways to solve two dataframe. Search stack overflow on how to merge two datasets – Joe Ferndz Nov 30 '20 at 06:41

1 Answers1

3

You can join them with a simple concat function.

both_tables = pd.concat([report1, report2])

both_tables

Example

First table

import pandas as pd

df1 = pd.DataFrame([
['1', 'Fares', 32, True],
['2', 'Elena', 23, False],
['3', 'Steven', 40, True]])

df1.columns = ['id', 'name', 'age', 'decision']

df1

enter image description here

Second table

df2 = pd.DataFrame([
['4', 'Max', 24, True],
['5', 'Elena', 20, False],
['6', 'Steven', 40, True]])

df2.columns = ['id', 'name', 'age', 'decision']

df2

enter image description here

Joining both tables togehter

df3 = pd.concat([df1, df2])

df3

enter image description here

I hope I could help you out a bit.

Maximilian Freitag
  • 939
  • 2
  • 10
  • 26