Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (17.6k points)

Is it possible to append to an empty data frame that doesn't contain any indices or columns?

I have tried to do this, but keep getting an empty dataframe at the end.

e.g.

df = pd.DataFrame()

data = ['some kind of data here' --> I have checked the type already, and it is a dataframe]

df.append(data)

The result looks like this:

Empty DataFrame

Columns: []

Index: []

1 Answer

0 votes
by (41.4k points)

This below code will work:

>>> df = pd.DataFrame()

>>> data = pd.DataFrame({"A": range(3)})

>>> df.append(data)

   A

0  0

1  1

2  2

You can store the output if you want:

>>> df

Empty DataFrame

Columns: []

Index: []

>>> df = df.append(data)

>>> df

   A

0  0

1  1

2  2

Related questions

0 votes
1 answer
0 votes
2 answers
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...