Answer to Question #276337 in Mechanical Engineering for Nobody

Question #276337

Discuss different ways of creating a series in python programming



languages using panda library. Justify your answer with the help of



suitable example

1
Expert's answer
2021-12-15T17:29:01-0500

1 It is possible to create empty dataset 

df = pandas.DataFrame()

2 Data frame from a list 

lst = ['a', 'b', 'c']
df = pandas.DataFrame(lst)

3 Create dataset from a dictionary

d = {'country': ['France', 'Spain', 'Italy'], 'capital': ['Paris', 'Madrid', 'Rome']}
df = pandas.DataFrame(d)

4 Read from a csv file

df = pandas.read_csv('filename.csv')

5 List if dictionaries

data = [{'a': 1, 'b': 2, 'c':3},
        {'a':10, 'b': 20, 'c': 30}]
df = pandas.DataFrame(data)

6 Using zip() function 

Countries = ['France', 'Spain', 'Italy']
Capitals = ['Paris', 'Madrid', 'Rome']
lst = list(zip(Countries, Capitals)) 
df = pandas.DataFrame(lst, columns = ['Country', 'Capital'])

7 From a series

d = {'one' : pandas.Series([10, 20, 30, 40],
                       index =['a', 'b', 'c', 'd']),
      'two' : pandas.Series([10, 20, 30, 40],
                        index =['a', 'b', 'c', 'd'])}
df = pandas.DataFrame(d)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS