Welcome to the Simplilearn Community

Want to join the rest of our members? Sign up right away!

Sign Up

Data Science with Python | Sujata| Apr 19,20,21,22,23,26,27,28,29,30 May 3,4,5,6,7

stg1 = "Hi"
stg2 = "How"
stg3 = "Are"
stg4 = "You"
msg = "()! () ()?".format(stg1, stg2, stg3, stg4)
print(msg)

Why I am not getting desired output like "Hi! How Are You?"
Getting output as "()! () ()?"
 
Hi Sayantan Majumder.

CASE 1: Using the print command directly without assigning the variables to msg

stg1 = "Hi"
stg2 = "How"
stg3 = "Are"
stg4 = "You"
print(stg1,"!",stg2,stg3,stg4,"?")

The above code will give the result as follows:

Hi ! How Are You ?

CASE 2: Using the + symbol also you can try as follows. (For space I am not sure, so add it manually for now)

stg1 = "Hi! "
stg2 = "How "
stg3 = "Are "
stg4 = "You "
stg5 = "?"
msg = stg1 + stg2 + stg3 + stg4 + stg5
print(msg)

Hi! How Are You ?

Thanks,
Krishna
 
stg1 = "Hi"
stg2 = "How"
stg3 = "Are"
stg4 = "You"
msg = "()! () ()?".format(stg1, stg2, stg3, stg4)
print(msg)

Why I am not getting desired output like "Hi! How Are You?"
Getting output as "()! () ()?"
Hello, Sayantan.. you have assign "()!()()?" to "msg" and you are printing that as "print(msg)" that is why you are getting output as ()!()()?
 

PankajaSL

Member
stg1 = "Hi"
stg2 = "How"
stg3 = "Are"
stg4 = "You"
msg = "()! () ()?".format(stg1, stg2, stg3, stg4)
print(msg)

Why I am not getting desired output like "Hi! How Are You?"
Getting output as "()! () ()?"
Try with this
stg1 = "Hi ! "
stg2 = "How "
stg3 = "Are "
stg4 = "You ?"
#msg = "()! () ()?".format(stg1, stg2, stg3, stg4)
#print(msg)
print("{}{}{}{}".format(stg1,stg2,stg3,stg4))

O/P : Hi ! How Are You ?
for .format we shd provide {} not ()
 
b=10.9
b=float(b)
b=str(b)
b=float(b)
print(type(b),b+10)

above code is working and given result as
<class 'float'> 20.9

---------------------------------------
But below code is giving me error why even we can add Int + Float. there is only change is int and float both data type is mention

b = 10.9
b = float(b)
b = str(b) # '10'
b = int(b)

print( type(b), b+10)

Result is below:

---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-17-01c2ad2a3414> in <module>
4 b = float(b)
5 b = str(b) # '10'
----> 6 b = int(b)
7
8 print( type(b), b+10)

ValueError: invalid literal for int() with base 10: '10.9'
 
import smtplib, ssl

# Create a secure SSL context
context = ssl.create_default_context()

smtObj=smtplib.SMTP('smtp.gmail.com', 587)
smtObj.ehlo()
smtObj.starttls(context=context) # Secure the connection
smtObj.login('<sender mail ID>', '<password>')
smtObj.sendmail('<sender mail ID>','<receiver mail id>','Subject: Script_Mail. \n Hello Sayantan')
smtObj.quit()

====================
Above code give me error as
Traceback (most recent call last):
File "C:\Users\tvlab\PycharmProjects\pythonProject\HeloWorld\app.py", line 6, in <module>
smtObj=smtplib.SMTP('smtp.gmail.com', 587)
File "C:\Users\tvlab\AppData\Local\Programs\Python\Python39\lib\smtplib.py", line 255, in __init__
(code, msg) = self.connect(host, port)
File "C:\Users\tvlab\AppData\Local\Programs\Python\Python39\lib\smtplib.py", line 341, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Users\tvlab\AppData\Local\Programs\Python\Python39\lib\smtplib.py", line 312, in _get_socket
return socket.create_connection((host, port), timeout,
File "C:\Users\tvlab\AppData\Local\Programs\Python\Python39\lib\socket.py", line 843, in create_connection
raise err
File "C:\Users\tvlab\AppData\Local\Programs\Python\Python39\lib\socket.py", line 831, in create_connection
sock.connect(sa)
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
 
*************Assignment 01**************
++++++++++++++++++++++++++
import pandas as pd
import numpy as np


#open file and read the file
df_faa_dataset= pd.read_csv('faa_ai_prelim.csv')
df_faa_dataset


#Display columns name
df_faa_dataset.columns


#now create a new data frame with only required columns
df_faa_analyze_dataset=df_faa_dataset[['ACFT_MAKE_NAME','LOC_STATE_NAME','ACFT_MODEL_NAME','RMK_TEXT',
'FLT_PHASE','EVENT_TYPE_DESC','FATAL_FLAG']]
df_faa_analyze_dataset


#replace all NaN for Fatal_flag with 'No'
df_faa_analyze_dataset.fillna('No')
df_faa_analyze_dataset


#group by aircraft name
aircraftType = df_faa_analyze_dataset.groupby('ACFT_MAKE_NAME')
aircraftType.size()


#drop values where ACFT_MAKE_NAME (aircraft make name) is not available
df_faa_final_dataset = df_faa_analyze_dataset.dropna(subset=['ACFT_MAKE_NAME'])
df_faa_final_dataset.head(50)


#Now group the dataset by fatal flag
fatalAccidents = df_faa_final_dataset.groupby('FATAL_FLAG')
fatalAccidents.size()


# inserting new column at data frame with value NaN
df_faa_newcolumn_dataset = df_faa_final_dataset.copy()
df_faa_newcolumn_dataset.insert(4, "New_Column", "NaN")


df_faa_newcolumn_dataset
 
# Drop Row multiple rows permanently
df_faa_final_dataset.drop(df_faa_final_dataset.index[5:20], inplace = True)

The above code throws below error

c:\users\tvlab\appdata\local\programs\python\python39\lib\site-packages\pandas\core\frame.py:4308: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
return super().drop(
 
Last edited:
Mam can you please answer the below questions in pandas assignment

#Skip the duplicate header row
#Verify if the dataset is fixed
#View the data statistics
 

_82982

New Member
Hello Mam,

Am not able to login today, right from6 am, dashboard is blank for me. kindly guide me to whom i have to contact, by sending mail/contact no.
 

Attachments

  • 1619491506321.png
    1619491506321.png
    50.4 KB · Views: 3

Naveen Boosa

New Member
may i know the what is the reason for this error
any one of file is not opening ,for all the files same error getting....

---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-13-68d0ffddb8dd> in <module>
----> 1 df=pd.read_csv('comcast.csv')
2 df.head(10)

~\anaconda3\lib\site-packages\pandas\io\parsers.py in read_csv(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, cache_dates, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, dialect, error_bad_lines, warn_bad_lines, delim_whitespace, low_memory, memory_map, float_precision)
684 )
685
--> 686 return _read(filepath_or_buffer, kwds)
687
688

~\anaconda3\lib\site-packages\pandas\io\parsers.py in _read(filepath_or_buffer, kwds)
450
451 # Create the parser.
--> 452 parser = TextFileReader(fp_or_buf, **kwds)
453
454 if chunksize or iterator:

~\anaconda3\lib\site-packages\pandas\io\parsers.py in __init__(self, f, engine, **kwds)
944 self.options["has_index_names"] = kwds["has_index_names"]
945
--> 946 self._make_engine(self.engine)
947
948 def close(self):

~\anaconda3\lib\site-packages\pandas\io\parsers.py in _make_engine(self, engine)
1176 def _make_engine(self, engine="c"):
1177 if engine == "c":
-> 1178 self._engine = CParserWrapper(self.f, **self.options)
1179 else:
1180 if engine == "python":

~\anaconda3\lib\site-packages\pandas\io\parsers.py in __init__(self, src, **kwds)
2006 kwds["usecols"] = self.usecols
2007
-> 2008 self._reader = parsers.TextReader(src, **kwds)
2009 self.unnamed_cols = self._reader.unnamed_cols
2010

pandas\_libs\parsers.pyx in pandas._libs.parsers.TextReader.__cinit__()

pandas\_libs\parsers.pyx in pandas._libs.parsers.TextReader._setup_parser_source()

FileNotFoundError: [Errno 2] No such file or directory: 'comcast.csv'
 
sns.pairplot(pd_dataset_auto[["mpg", "weight", "origin"]], size= 3)
sns.pairplot(pd_dataset_auto[["mpg", "weight", "origin"]], hue ="origin", size= 3)

Graph got changed introducing HUE parameter
 

Attachments

  • withoutHue.png
    withoutHue.png
    35 KB · Views: 3
  • withHue.png
    withHue.png
    61.4 KB · Views: 3

_33963

New Member
Logistic Regression titanic have a column "Survived as Yes/No instead of numeric, how do we go about the target variables.
 
For Third project (Comcast Telecom )
Which state has the highest percentage of unresolved complaints ?

My understanding for this req is that we need to have the state with
maximum percentage on unresolved tickets.

total number of open complaints /total number complaints

It became Kansas with 50 %
 

Manoj Govind Dhanuka

Customer
Customer
Hi Sujata - Please find attached the solution that I had built for Project 1. Kindly review the work and help me with the question #5 involving Statistical test. I am currently getting a p-value of 0 but I am not sure if I had done this correctly.
Thanks!
 

Divya.Akanksha

Customer
Customer
I have a question on outliers... when we are removing the outlier... and replacing with the mean value, it may be that is the actual data, and we are not considering that. it may manipulate the actual data
 
Project_Assignment1
=============================

#import the required libraries
import warnings
warnings.filterwarnings('ignore')

import matplotlib.pyplot as plt
import pandas as pd

#import the Service_Request dataset
df_ServiceRequest_data = pd.read_csv('311_Service_Requests_from_2010_to_Present.csv')

# Convert the columns ‘Created Date’ and Closed Date’ to datetime datatype and store in same column
df_ServiceRequest_data['Created Date'] = pd.to_datetime(df_ServiceRequest_data['Created Date'])
df_ServiceRequest_data['Closed Date'] = pd.to_datetime(df_ServiceRequest_data['Closed Date'])

df_ServiceRequest_data['Request_closing_time'] = df_ServiceRequest_data['Closed Date'] - df_ServiceRequest_data['Created Date']

# Conver request closing time in minute
df_ServiceRequest_data['Request_closing_time_minute'] = df_ServiceRequest_data['Request_closing_time'].dt.seconds/60

df_ServiceRequest_Location =df_ServiceRequest_data.groupby(['City','Location Type'])['Complaint Type'].value_counts().to_frame().rename(columns={'Complaint Type':'Count'})
df_ServiceRequest_Location

df_ServiceRequest_Location.reset_index(inplace=True)

fig=plt.figure(figsize=(8,8))
plt.pie( df_ServiceRequest_Location['Complaint Type'] ,# data
labels = df_ServiceRequest_Location['Location Type'] );

plt.show()

======================================

ValueError Traceback (most recent call last)
<ipython-input-93-2e762a55a10b> in <module>
3
4 fig=plt.figure(figsize=(8,8))
----> 5 plt.pie( df_ServiceRequest_Location['Complaint Type'] ,# data
6 labels = df_ServiceRequest_Location['Location Type'] );
7

c:\users\tvlab\appdata\local\programs\python\python39\lib\site-packages\matplotlib\pyplot.py in pie(x, explode, labels, colors, autopct, pctdistance, shadow, labeldistance, startangle, radius, counterclock, wedgeprops, textprops, center, frame, rotatelabels, normalize, data)
2973 textprops=None, center=(0, 0), frame=False,
2974 rotatelabels=False, *, normalize=None, data=None):
-> 2975 return gca().pie(
2976 x, explode=explode, labels=labels, colors=colors,
2977 autopct=autopct, pctdistance=pctdistance, shadow=shadow,

c:\users\tvlab\appdata\local\programs\python\python39\lib\site-packages\matplotlib\__init__.py in inner(ax, data, *args, **kwargs)
1350 def inner(ax, *args, data=None, **kwargs):
1351 if data is None:
-> 1352 return func(ax, *map(sanitize_sequence, args), **kwargs)
1353
1354 bound = new_sig.bind(ax, *args, **kwargs)

c:\users\tvlab\appdata\local\programs\python\python39\lib\site-packages\matplotlib\axes\_axes.py in pie(self, x, explode, labels, colors, autopct, pctdistance, shadow, labeldistance, startangle, radius, counterclock, wedgeprops, textprops, center, frame, rotatelabels, normalize)
3027 # The use of float32 is "historical", but can't be changed without
3028 # regenerating the test baselines.
-> 3029 x = np.asarray(x, np.float32)
3030 if x.ndim > 1:
3031 raise ValueError("x must be 1D")

c:\users\tvlab\appdata\local\programs\python\python39\lib\site-packages\numpy\core\_asarray.py in asarray(a, dtype, order, like)
100 return _asarray_with_like(a, dtype=dtype, order=order, like=like)
101
--> 102 return array(a, dtype, copy=False, order=order)
103
104

c:\users\tvlab\appdata\local\programs\python\python39\lib\site-packages\pandas\core\series.py in __array__(self, dtype)
766 dtype='datetime64[ns]')
767 """
--> 768 return np.asarray(self.array, dtype)
769
770 # ----------------------------------------------------------------------

c:\users\tvlab\appdata\local\programs\python\python39\lib\site-packages\numpy\core\_asarray.py in asarray(a, dtype, order, like)
100 return _asarray_with_like(a, dtype=dtype, order=order, like=like)
101
--> 102 return array(a, dtype, copy=False, order=order)
103
104

c:\users\tvlab\appdata\local\programs\python\python39\lib\site-packages\pandas\core\arrays\numpy_.py in __array__(self, dtype)
201
202 def __array__(self, dtype=None) -> np.ndarray:
--> 203 return np.asarray(self._ndarray, dtype=dtype)
204
205 _HANDLED_TYPES = (np.ndarray, numbers.Number)

c:\users\tvlab\appdata\local\programs\python\python39\lib\site-packages\numpy\core\_asarray.py in asarray(a, dtype, order, like)
100 return _asarray_with_like(a, dtype=dtype, order=order, like=like)
101
--> 102 return array(a, dtype, copy=False, order=order)
103
104

ValueError: could not convert string to float: 'Drinking'
 
Top