Page 6 of 6
Re: Programming and Computing with Python Right from the Forum
Posted: Tue Aug 16, 2022 5:42 pm
by Eli
Testing Sample Module
import pandas as pd
#import random and use it as random.sample
from random import sample
#Let us create some data using sample from random module
#Create two lists
country_list = ["USA", "Russia","China","India"]
#Using the name list, let us create three variables using sample() function
top1 = sample(country_list,4)
top2 = sample(country_list,4)
top3 = sample(country_list,4)
#Now, we can use these lists to create a dataframe with 3 columns
df = pd.DataFrame({"Top1":top1,
"Top2":top2,
"Top3":top3,
})
print(df)
Re: Live Programming and Computing
Posted: Tue May 30, 2023 9:30 pm
by Eli
Here is a SnapPy, what is it ?
SnapPy is a program for studying the topology and geometry of 3-manifolds, with a focus on hyperbolic structures. It runs on Mac OS X, Linux, and Windows, and combines a link editor and 3D-graphics for Dirichlet domains and cusp neighborhoods with a powerful command-line interface based on the Python programming language.
SnapPy can be
installed on Linux as follows:
Ubuntu/Debian/Mint: Tested on Ubuntu 20.04:
sudo apt-get install python3-tk python3-pip
# Note no "sudo" on the next one!
python3 -m pip install --upgrade --user snappy
Users of Ubuntu 18.04 or older should do:
sudo apt-get install python3-tk python3-pip
# Note no "sudo" on the next two
python3 -m pip install --upgrade --user pip wheel
python3 -m pip install --upgrade --user snappy
On TSSFL Stack, SnapPy is installed and can be used via SageMath. We can at once import the whole Stack of SnapPy modules and start testing it immediatelly:
from snappy import Manifold, Triangulation, Manifold, ManifoldHP, AbelianGroup, FundamentalGroup, HolonomyGroup, HolonomyGroupHP, DirichletDomain, DirichletDomainHP, CuspNeighborhood, CuspNeighborhoodHP, SymmetryGroup, AlternatingKnotExteriors, NonalternatingKnotExteriors, SnapPeaFatalError, InsufficientPrecisionError, pari, twister, OrientableCuspedCensus, NonorientableCuspedCensus, OrientableClosedCensus, NonorientableClosedCensus, LinkExteriors, CensusKnots, HTLinkExteriors, TetrahedralOrientableCuspedCensus, TetrahedralNonorientableCuspedCensus, OctahedralOrientableCuspedCensus, OctahedralNonorientableCuspedCensus, CubicalOrientableCuspedCensus, CubicalNonorientableCuspedCensus, DodecahedralOrientableCuspedCensus, DodecahedralNonorientableCuspedCensus, IcosahedralNonorientableClosedCensus, IcosahedralOrientableClosedCensus, CubicalNonorientableClosedCensus, CubicalOrientableClosedCensus, DodecahedralNonorientableClosedCensus, DodecahedralOrientableClosedCensus, Crossing, Strand, Link, Tangle, RationalTangle, ZeroTangle, InfinityTangle, IdentityBraid, random_link, DTcodec
A = AbelianGroup(elementary_divisors=[5,15,0,0])
print(A)
print(A[0])
M = Manifold('m004')
print(M.symmetry_group())
M = Manifold('K7_1')
G = M.fundamental_group()
g = G.generators_in_originals()
print(g)
#M.inside_view()
To explore SnapPy Manifold class for example (unfortunately tinker is not installed on SageMath), open Ubuntu LInux Terminal and evoke Python/Ipython interpreter, import Manifold and execute the below simple code:
from snappy import Manifold
M = Manifold('m004')
M.inside_view()
%gui tk
#Code 2
from snappy import ManifoldHP
M = ManifoldHP('14n12345') #Try M = ManifoldHP('15n4321')
M.volume()
M.plink()
M.browse()
Re: Live Programming and Computing
Posted: Fri Jul 07, 2023 12:06 pm
by Eli
Re: Live Programming and Computing
Posted: Mon Sep 18, 2023 7:01 pm
by Eli
import pandas as pd
import re
# Sample data
data = {'date_time': ['Random text 2023-09-03 00:20:00 more text', 'Some other text', '2023-09-03 00:20:00 additional text']}
df = pd.DataFrame(data)
# Extract the first datetime occurrence with the desired format
pattern = r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}'
first_datetime = re.search(pattern, ' '.join(df['date_time']))
if first_datetime:
# Extract the time from the first datetime occurrence
first_time = first_datetime.group().split()[1]
print(first_time)
else:
print("Datetime not found in DataFrame.")
Re: Live Programming and Computing with Python, R, Sage, Octave, Maxima, Singular, Gap, GP, HTML & Macaulay2
Posted: Tue Dec 05, 2023 5:31 pm
by Eli
Python
Polars is an alternative to Pandas, written with performance in mind. Test it:
import polars as pl
from datetime import datetime
df = pl.DataFrame(
{
"integer": [1, 2, 3, 4, 5],
"date": [
datetime(2023, 1, 1),
datetime(2023, 1, 2),
datetime(2023, 1, 3),
datetime(2023, 1, 4),
datetime(2023, 1, 5),
],
"float": [4.0, 5.0, 6.0, 7.0, 8.0],
}
)
print(df)
print(df.sample(2))
print(df.describe())
Re: Live Programming and Computing with Python, R, Sage, Octave, Maxima, Singular, Gap, GP, HTML & Macaulay2
Posted: Fri Jan 19, 2024 8:36 am
by Eli
Test Vega Altair
# import altair with an abbreviated alias
import altair as alt
# load a sample dataset as a pandas DataFrame
from vega_datasets import data
cars = data.cars()
# make the chart
chart = alt.Chart(cars).mark_point().encode(
x='Horsepower',
y='Miles_per_Gallon',
color='Origin',
).interactive()
chart.save('chart.html') # Save to file
Re: Live Programming and Computing with Python, R, Sage, Octave, Maxima, Singular, Gap, GP, HTML & Macaulay2
Posted: Sat Jul 20, 2024 4:17 pm
by Eli
These libraries are currently available, test:
import langserve
import openai
import langchain
import langchain_openai
import sklearn
import fastapi
import flask
Re: Live Programming and Computing with Python, R, Sage, Octave, Maxima, Singular, Gap, GP, HTML & Macaulay2
Posted: Sat May 03, 2025 10:36 pm
by Eli
Use R and Python together - read data into R dataframe and then convert it to Pandas Dataframe:
import pandas as pd
from rpy2 import robjects
from rpy2.robjects import pandas2ri
#Read data in R
robjects.r('data <- read.csv("https://raw.githubusercontent.com/selva86/datasets/master/mtcars.csv")')
#Get the R data frame
r_data = robjects.r['data']
#Convert to pandas DataFrame
data_df = pandas2ri.rpy2py(r_data)
#Display the DataFrame
print(data_df.head())