In: Computer Science
Pandas exercises:
1. Write a python program using Pandas to create and display a
one-dimensional array-like object containing an array of
data.
2. Write a python program using Pandas to convert a Panda module
Series to Python list and print it's type. (Hint: use ds.tolist()
to convert the pandas series ds to a list)
3. Create a pandas dataframe called **my_df** with index as integer
numbers between 0 to 10, first column (titled "rnd_int") as 10
integer random numbers between 10-25, second column ("rnd_float")
as 10 random continuous numbers (not necessarily integer) between
15-40, and third column ("rnd_strBool") as 10 random string values
that are either "True" or "False" (Hint:
numpy.random.uniform(a,b,count) and
numpy.random.randint(a,b,size=count) can be helpful)
can you use google colab to do the code please
Python code screenshot for creating one-dimensional array like object containing array of data, with Sample Output:
Python code to copy:
# Create one-dimensional array like object containing array of data
import pandas as pd
ds = pd.Series([5, 32, 53, 64, 9, 242])
print(ds)
Python code screenshot for converting Series to List, with Sample Output
Python code to copy:
print(type(ds))
# convert the Python Series to Python lists
ls = ds.to_list()
print(ls)
print(type(ls))
Python code screenshot for Creating Dataframe:
Python code to copy:
from numpy import random
# Use pandas.random.randint for random integers in range
rnd_int = pd.Series(random.randint(10,25,10))
# Use pandas.random.uniform for random floats in given range
rnd_float = pd.Series(random.uniform(15,40,10))
# Use random.choice to select randomly from [ given list of elements]
rnd_strBool = pd.Series(random.choice(["True","False"],10))
# Create my_df dataframe
my_df = pd.DataFrame({"rnd_int" : rnd_int, "rnd_float" : rnd_float, "rnd_strBool" : rnd_strBool})
my_df