Answer to Question #275545 in Python for Sonu Rathore

Question #275545

Create a dataframe by using the dataset [tipsnew.csv] and perform the


following operations


a) Print the day value when the value of total_bill is maximum and


minimum.


b) Retrieve all the rows from dataframe when the value of tip is more


than 3.0 and less than 5.0


c) Print the time of the meal and gender of the person who paid the tip


more than 5.0


d) Select and display last 10 rows from the dataframe when customer


smoking habbit is ‘yes’


e) Create the newdataframe(ndf) from original dataframe(df)


containing all rows and the following columns [total_bill


tip, size].


Sort and display all values of column tip in ascendending order

1
Expert's answer
2021-12-05T18:17:43-0500
import pandas as pd



df = pd.read_csv(r"tipsnew.csv")
dataframe = pd.DataFrame(df)


total_bill = dataframe['total_bill']


total_bill_max = total_bill.max()
total_bill_min = total_bill.min()


index_max = dataframe.index[dataframe['total_bill'] == total_bill_max].tolist()
index_min = dataframe.index[dataframe['total_bill'] == total_bill_min].tolist()


print('\n a)')
print('Day maximum: ', dataframe.loc[index_max[0]]['day'])
print('Day minimum: ', dataframe.loc[index_min[0]]['day'])


b = dataframe[(dataframe.tip < 5.0) & (dataframe.tip > 3.0)]
print('\n b)')
print(b[['total_bill', 'tip', 'smoker', 'day', 'time', 'size']])


c = dataframe[dataframe.tip > 5.0]
print('\n c)')
print(c[['sex', 'tip']])



d = dataframe[dataframe.smoker == 'Yes']
print('\n d)')
print(d[-10:])


newdataframe = dataframe[['total_bill', 'tip', 'size']]
print('\n e)')
print(newdataframe)

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