Python Pandas Exercises

Pandas: Append data to an empty DataFrame

Pandas: DataFrame Exercise-49 with Solution

Write a Pandas program to append data to an empty DataFrame.

Sample Solution :-

Python Code :

import pandas as pd
import numpy as np
df = pd.DataFrame()
data = pd.DataFrame({"col1": range(3),"col2": range(3)})
print("After appending some data:")
df = df.append(data)

Sample Output:

After appending some data:
   col1  col2
0     0     0
1     1     1
2     2     2         

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Pandas program to get the datatypes of columns of a DataFrame.
Next: Write a Pandas program to sort a given DataFrame by two or more columns.

What is the difficulty level of this exercise?

New Content: Composer: Dependency manager for PHP, R Programming

bedava porno