1. Write both TCP client and TCP server in Python version 3.8 or above.
2. Test the network connectivity between TCP client and TCP server.
3. Import the CSV file into the TCP server.
4. Find the number of rows and columns of the data set, and display the results on the TCP client
machine.
5. Output the 2
nd row on the TCP client machine.
6. Find the averages(mean) of the statistics for NBA players and display the results on the TCP
client machine.
import socket
import pandas as pd
if __name__ == "__main__":
ip = "127.0.0.1"
port = 1234
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind((ip, port))
server.listen(5)
while True:
client, address = server.accept()
print(f"Connection Estabished - {address[0]}:{address[1]}")
df = pd.read_csv(r"nba.csv")
rows = str(len(df.index))
colomns = str(len(df.columns))
second_rows = df.head()
second_rows = second_rows[1:2]
mean_salary = df['Salary'].mean()
client.send(bytes(rows, encoding='utf8'))
client.send(bytes(colomns, encoding='utf8'))
client.send(bytes(str(second_rows), encoding='utf8'))
client.send(bytes(str(mean_salary), encoding='utf8
import socket
import pandas as pd
if __name__ == "__main__":
ip = "127.0.0.1"
port = 1234
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.connect((ip, port))
rows = server.recv(1024).decode('utf-8')
colomns = server.recv(1024).decode('utf-8')
second_rows = server.recv(1024).decode('utf-8')
mean_salary = server.recv(1024).decode('utf-8')
print('Rows: ', rows)
print('Colomns: ', colomns)
print('Second row: \n', second_rows)
print('Mean salary: ', mean_sala
Comments
Leave a comment