Discuss different ways of creating a dataframe in python programming
languages using panda library. Justify your answer with the help of
suitable example.
# Import pandas library
import pandas as pd
 Â
# initialize list of lists
data = [['tom', 10], ['nick', 15], ['juli', 14]]
 Â
# Create the pandas DataFrame
df = pd.DataFrame(data, columns = ['Name', 'Age'])
 Â
# print dataframe.
dict_a = {
'col_a': np.random.randint(100, size=500),
'col_b': np.random.random(500),
'col_c': np.random.randn(500)
}
df = pd.DataFrame(dict_a)
print(df.shape)
(500, 3)
df.head()
Comments
Leave a comment