How to copy a specific line of date frame to another date frame

1

I have following Data Frame:

data = {
'País': ['Bélgica', 'Índia', 'Brasil','Índia','Bélgica','Bélgica','Russia','Brasil'],
'Capital': ['Bruxelas1', 'Nova Delhi', 'Brasília', 'Nova Delhi','Bruxelas2','Bruxelas3','Moscou','Brasília'],
'Continente': ['Europa', 'Asia', 'America do Sul', 'Asia','Europa','Europa','Europa','America do Sul'],
'População': [123465, 456789, 987654, 456789,123465,123465,350000000,987654]}
df = pd.DataFrame(data, columns=['País','Capital','Continente','População'])

df1 = df.loc[0]

df1 is a series (pandas.core.series.Series). . I need df1 to be data frame

    
asked by anonymous 09.10.2017 / 17:43

1 answer

0

Hello,

If you are trying to trim the dataframe by indexes, use df.iloc[linha, coluna] . loc is used when you want to trim with a column name or a line value.

To convert a pandas.Series to a pandas.DataFrame , just call the pandas.Series.to_frame() function as explained here in the documentation: link

I hope I have helped.

    
24.10.2017 / 22:10