Both columns on the plot are not of numeric type, however directives
(.env) boris@boris-All-Series:~/MATPLOTLIBSR/TENSOR$ cat SortedPandasD1.py
Both columns on the plot are not of numeric type, however directives
(.env) boris@boris-All-Series:~/MATPLOTLIBSR/TENSOR$ cat SortedPandasD1.py
First run
$ sudo apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virtinst virt-manager
Enable and start daemon libvirtd
$ sudo usermod -aG libvirt $USER
$ sudo usermod -aG kvm $USERSet up WebCocpit Console $ sudo vi /etc/apt/sources.listAdd linedeb http://archive.ubuntu.com/ubuntu \focal-backports main restricted universe multiverse:wq $ sudo apt-get update
$ sudo apt install firewalld
$ sudo systemctl start firewalld
$ sudo systemctl enable firewalld
$ sudo systemctl status firewalld
$ sudo apt-get install -t focal-backports cockpit
$ sudo apt install -t focal-backports cockpit-machines
$ sudo systemctl start cockpit.socket
$ sudo systemctl status cockpit.socket
$ sudo systemctl enable cockpit.socket
$ sudo firewall-cmd --add-service=cockpit --permanent
$ sudo firewall-cmd --reload
The following below is a not entirely trivial algorithm for students that creates a Python dictionary after scanning text according to the conditions of the problem, which gets converted into Pandas Dataframe and uploaded to SQLite database table to be analyzed via nested SQL Query.
Problem itself
A text file (beta-wide.txt) consists of many lines, each of which can contain letters from the set A, B, C, D, E, F. For the entire file, you need to determine which letter is most often forms substrings of maximum length. As an answer, you must enter a string consisting of the found letters, alphabetically without delimiters
(.env) [boris@fedora34server WORK]$ ll beta-wide.txt
-rw-rw-r--. 1 boris boris 59420 Dec 23 16:20 beta-wide.txt
Python code building dictionary to be uploaded into SQLite table
via pandas DataFrame
import pandas as pd
import sqlite3
connection = sqlite3.connect('data_pandas.db')
c = connection.cursor()
c.execute('CREATE TABLE IF NOT EXISTS results(symv_name text, symv_qnt number)')
connection.commit()
seqLetter = []
file = open('./beta-wide.txt')
for line in file:
currLetrs = set()
curLen = 0
maxLen = 1
prev = ' '
for next in line:
if prev == next:
curLen +=1
if curLen > maxLen:
maxLen = curLen
currLetrs = set([next])
elif maxLen == curLen:
currLetrs.add(next)
else:
curLen =1
prev = next
seqLetter = seqLetter + list(currLetrs)
d = {}
for i in set(seqLetter):
key = i
d[key] = d[key] = d.get(key,0) + seqLetter.count(i)
data_items = d.items()
data_list = list(data_items)
df = pd.DataFrame(data_list, columns= ['symv_name','symv_qnt'])
df.to_sql('results', connection, if_exists='replace', index = False)
query = "SELECT * FROM results WHERE symv_qnt = (SELECT max(symv_qnt) FROM results)"
data = pd.read_sql_query(query,connection)
print(data)
The following below is a not entirely trivial algorithm for students that creates a Python dictionary when scanning text according to the conditions of the problem, which is then processed as Pandas Dataframe to provide the output required
The original problem itself
The text file alpha-wide.txt contains only capital letters of the Latin alphabet (ABC… Z). Identify the character that most often occurs in the file immediately after the letter X. In the answer first write down this character, and then separate by blank how many times it occurred after letters X. If there are several such characters, you need to display the one that appears earlier in the alphabet.
The file alpha-wide.txt contains a pretty long string
Python code has been set up in a virtual environment with pandas installed via pip
import pandas as pd
with open("./alpha-wide.txt") as F:
string = F.readline() # getting next line
d={} # declare dictionary of letters
while "X" in string:
n = string.find("X") # index "X"
key = string[n+1] # create key = Letter
d[key] = d.get(key,0)+1
string = string[n+1:] # slice, form a new line
# print(d)
data_items = d.items()
data_list = list(data_items)
df = pd.DataFrame(data_list,columns = ['X1','Y1'])
df.sort_values("Y1", axis = 0, ascending = True, inplace = True, na_position ='last')
print("DataFrame has been sorted by Y1")
print(df)
The following below is a not entirely trivial algorithm for students that creates a Python dictionary when scanning text according to the conditions of the problem, which is then processed as Pandas Dataframe to provide the output required
The original problem itself
The text file alpha-wide.txt contains only capital letters of the Latin alphabet (ABC… Z). Identify the character that most often occurs in the file immediately after the letter X. In the answer first write down this character, and then separate by blank how many times it occurred after letters X. If there are several such characters, you need to display the one that appears earlier in the alphabet.
The file alpha-wide.txt contains a pretty long string
Python code has been set up in a virtual environment with pandas installed via pip
import pandas as pd
with open("./alpha-wide.txt") as F:
string = F.readline() # getting next line
d={} # declare dictionary of letters
while "X" in string:
n = string.find("X") # index "X"
key = string[n+1] # create key = Letter
d[key] = d.get(key,0)+1
string = string[n+1:] # slice, form a new line
# print(d)
data_items = d.items()
data_list = list(data_items)
df = pd.DataFrame(data_list,columns = ['X1','Y1'])
df.sort_values("Y1", axis = 0, ascending = True, inplace = True, na_position ='last')
print("DataFrame has been sorted by Y1")
print(df)
We intend to rely on https://github.com/mathbunnyru/python-cpp-extension . We also would to convert lists to sets and vice-versa and utilize method set1.difference(set2) . Sometimes Python tricks make you really excited
Download and extract tarball on Fedora 34 with "C Development tools" and python-devel installed . Setup python venv in your working directory
$ python3 -m venv .env
$ source .env/bin/activate
$ python setup.py install
This post is an immediate follow up for http://lxer.com/module/newswire/view/306255/index.html what will result significant performance boost vs python's version of the sieve of Eratosthenes procedure.
We intend to rely on https://github.com/mathbunnyru/python-cpp-extension . Download and extract tarball on Fedora 34 with "C Development tools" and python-devel installed . Setup python venv in your working directory
$ python3 -m venv .env
$ source .env/bin/activate
$ python setup.py install
(.env) [boris@fedora34server python-cpp-extension-delta]$ ll
total 36
drwxrwxr-x. 5 boris boris 89 Oct 10 09:37 build
drwxrwxr-x. 2 boris boris 90 Oct 10 09:37 cpp_python_extension.egg-info
-rw-rw-r--. 1 boris boris 751 Oct 10 11:57 delta16.py
-rw-rw-r--. 1 boris boris 414 Oct 10 12:01 deltaBetween.py
drwxrwxr-x. 2 boris boris 61 Oct 10 09:37 dist
-rw-rw-r--. 1 boris boris 85 Oct 10 09:18 MyProg.py
-rw-rw-r--. 1 boris boris 1192 Oct 10 09:18 README.md
-rw-rw-r--. 1 boris boris 682 Oct 10 09:18 setup.py
-rw-rw-r--. 1 boris boris 450 Oct 10 09:18 sieve.cpp
-rw-rw-r--. 1 boris boris 140 Oct 10 09:18 sieve.h
-rw-rw-r--. 1 boris boris 1542 Oct 10 09:18 sieve_python_wrapper.cpp
-rw-rw-r--. 1 boris boris 200 Oct 10 09:18 test_benchmark.py
(.env) [boris@fedora34server python-cpp-extension-delta]$
Now update delta16.py from post http://lxer.com/module/newswire/view/306255/index.html
Then update delta16.py as follows
(.env) [boris@fedora34server python-cpp-extension-delta]$ cat delta16.py
import cpp_python_extension
def sumDigits(N,k):
sum = 0
while (N != 0):
sum = sum + N % k
N = N // k
return sum
def SearchNumber(uplimit,sdg):
imax = 0
zn = []
# Here we invoke cpp_python_extension.sieve_of_eratosthenes
# been written in C++ via Python C API which returns python's
# object list containing all prime numbers <= uplimit
zn = cpp_python_extension.sieve_of_eratosthenes(uplimit)
spisok = set(zn)
for i in range(2,uplimit):
# Look for highest prime number <= uplimit
# and summa of digits <= sdg
if (i in spisok) and sumDigits(i,10) <= sdg:
if i > imax:
imax = i
print("Maximum = ",imax)
def main():
uplimit,sdg = 0,0
uplimit = int(input("Input range of scan :"))
sdg = int(input("Input sum of digits :"))
SearchNumber(uplimit,sdg)
if __name__ == "__main__":
main()