Professional Documents
Culture Documents
Exp 8
Exp 8
Exp 8
1) Create a dataframe of ten rows, four columns with random values. Write a Pandas program to
highlight the negative numbers red and positive numbers black.
The seed() method is used to initialize the random number generator. The
random number generator needs a number to start with (a seed value), to be able
to generate a random number. By default the random number generator uses the
current system time.
import pandas as pd
import numpy as np
np.random.seed(24)
axis=1)
print("Original array:")
print(df)
def color_negative_red(val):
df.style.applymap(color_negative_red)
2) Create a dataframe of ten rows, four columns with random values. Write a Pandas program to
highlight the maximum value in each column.
The iloc indexer for Pandas Dataframe is used for integer-location based
indexing / selection by position. The iloc indexer syntax is data.iloc[<row
selection>, <column selection>], which is sure to be a source of confusion for R
users.
import pandas as pd
import numpy as np
np.random.seed(24)
axis=1)
df.iloc[0, 2] = np.nan
df.iloc[3, 3] = np.nan
df.iloc[4, 1] = np.nan
df.iloc[9, 4] = np.nan
print("Original array:")
print(df)
def highlight_max(s):
'''
'''
is_max = s == s.max()
import pandas as pd
import numpy as np
df
import pandas as pd
import numpy as np
np.random.seed(24)
df = pd.DataFrame({'A': np.linspace(1, 10, 10)})
axis=1)
df.iloc[0, 2] = np.nan
df.iloc[3, 3] = np.nan
df.iloc[4, 1] = np.nan
df.iloc[9, 4] = np.nan
print("Original array:")
print(df)
def highlight_cols(s):
color = 'grey'