Live Programming and Computing with Python, R, Sage, Octave, Maxima, Singular, Gap, GP, HTML & Macaulay2

User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5334
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#51

Testing Sample Module

  1. import pandas as pd
  2. #import random and use it as random.sample
  3. from random import sample
  4.  
  5. #Let us create some data using sample from random module
  6. #Create two lists
  7. country_list = ["USA", "Russia","China","India"]
  8.  
  9. #Using the name list, let us create three variables using sample() function
  10. top1 = sample(country_list,4)
  11. top2 = sample(country_list,4)
  12. top3 = sample(country_list,4)
  13.  
  14. #Now, we can use these lists to create a dataframe with 3 columns
  15. df = pd.DataFrame({"Top1":top1,
  16.               "Top2":top2,
  17.               "Top3":top3,
  18.              })
  19. print(df)

0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5334
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#52

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:

  1. sudo apt-get install python3-tk python3-pip
  2. # Note no "sudo" on the next one!
  3. python3 -m pip install --upgrade --user snappy

Users of Ubuntu 18.04 or older should do:

  1. sudo apt-get install python3-tk python3-pip
  2. # Note no "sudo" on the next two
  3. python3 -m pip install --upgrade --user pip wheel
  4. 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:

  1. 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
  2.  
  3. A = AbelianGroup(elementary_divisors=[5,15,0,0])
  4. print(A)
  5. print(A[0])
  6.  
  7. M = Manifold('m004')
  8. print(M.symmetry_group())
  9.  
  10. M = Manifold('K7_1')
  11. G = M.fundamental_group()
  12. g = G.generators_in_originals()
  13. print(g)
  14. #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:

  1. from snappy import Manifold
  2. M = Manifold('m004')
  3. M.inside_view()
  4. %gui tk
  5.  
  6. #Code 2
  7. from snappy import ManifoldHP
  8. M = ManifoldHP('14n12345') #Try M = ManifoldHP('15n4321')
  9. M.volume()
  10. M.plink()
  11. M.browse()

0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5334
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#53

0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5334
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#54

  1. import pandas as pd
  2. import re
  3.  
  4. # Sample data
  5. data = {'date_time': ['Random text 2023-09-03 00:20:00 more text', 'Some other text', '2023-09-03 00:20:00 additional text']}
  6. df = pd.DataFrame(data)
  7.  
  8. # Extract the first datetime occurrence with the desired format
  9. pattern = r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}'
  10. first_datetime = re.search(pattern, ' '.join(df['date_time']))
  11.  
  12. if first_datetime:
  13.     # Extract the time from the first datetime occurrence
  14.     first_time = first_datetime.group().split()[1]
  15.     print(first_time)
  16. else:
  17.     print("Datetime not found in DataFrame.")

0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5334
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#55

Python Polars is an alternative to Pandas, written with performance in mind. Test it:

  1. import polars as pl
  2.  
  3. from datetime import datetime
  4.  
  5. df = pl.DataFrame(
  6.     {
  7.         "integer": [1, 2, 3, 4, 5],
  8.         "date": [
  9.             datetime(2023, 1, 1),
  10.             datetime(2023, 1, 2),
  11.             datetime(2023, 1, 3),
  12.             datetime(2023, 1, 4),
  13.             datetime(2023, 1, 5),
  14.         ],
  15.         "float": [4.0, 5.0, 6.0, 7.0, 8.0],
  16.     }
  17. )
  18.  
  19. print(df)
  20.  
  21. print(df.sample(2))
  22. print(df.describe())

0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5334
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#56

Test Vega Altair

  1. # import altair with an abbreviated alias
  2. import altair as alt
  3.  
  4. # load a sample dataset as a pandas DataFrame
  5. from vega_datasets import data
  6. cars = data.cars()
  7.  
  8. # make the chart
  9. chart = alt.Chart(cars).mark_point().encode(
  10.     x='Horsepower',
  11.     y='Miles_per_Gallon',
  12.     color='Origin',
  13. ).interactive()
  14.  
  15. chart.save('chart.html') # Save to file

0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
Post Reply
  • Similar Topics
    Replies
    Views
    Last post

Return to “Technologies for Teaching, Learning, Research, Problem Solving and Business”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 12 guests