Re: TIME IN XARRAY

2021-04-18 Thread Gys

On 4/15/21 7:58 PM, Jorge Conforte wrote:



Hi,


I'm using xarray to read netcdf data and I had to time in my data the 
values:



xarray.DataArray 'time' (time: 507)>
array(['1979-01-01T00:00:00.0', '1979-02-01T00:00:00.0',
    '1979-03-01T00:00:00.0', ..., 
'2021-01-01T00:00:00.0',

    '2021-02-01T00:00:00.0', '2021-03-01T00:00:00.0'],
   dtype='datetime64[ns]')


Please, how can I get the years and months values from this array.


Thanks,


Conrado


Hi,
maybe this :

from datetime import datetime
import time
# Convert Event to a string
Event="1979-01-01T00:00:00.0"
strDate=time.strftime(Event)
print("Date string ",strDate)
# Get the Year from the string strDate
print("Year ",strDate[0:4])
# Get the month from the string strDate
print("Month ",strDate[5:7])
print()
#
# Convert Event to a datetime object
Event="1979-01-01T00:00:00.0"
dtmDate=datetime.strptime(Event,"%Y-%m-%dT%H:%M:%S.0")
print("datetime object",dtmDate)
# Get the Year from the datetime object
print("Year ",dtmDate.year)
# Get the month from the datetime object
print("Month ",dtmDate.month)

-hth
Gys

--
https://mail.python.org/mailman/listinfo/python-list


Re: file location/directory

2021-03-16 Thread Gys

On 3/14/21 7:44 PM, Quentin Bock wrote:

how can I change the path that python takes to run certain files, I'm
starting to create game and I want those in separate folders, so how can I
change it so that python runs the program with the files from that folder?

<https://www.avast.com/sig-email?utm_medium=email_source=link_campaign=sig-email_content=webmail_term=icon>
Virus-free.
www.avast.com
<https://www.avast.com/sig-email?utm_medium=email_source=link_campaign=sig-email_content=webmail_term=link>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>


Hi Quentin Bock,
this is a very dense subject. The simplest sulution is to create a 
MainFolder with the main module of your game. Then in that folder, 
create a SubFolder where you can store the modules your game wants to 
import.


The alternative is to use the Environment variable $PYTHONPATH

<https://scipher.wordpress.com/2010/05/10/setting-your-pythonpath-environment-variable-linuxunixosx/>

Setting Your PYTHONPATH environment variable (Linux/Unix/OsX)

Open your personal .bashrc file at /home//.bashrc
Note that this is a hidden file
Add these 2 lines :

PYTHONPATH="${PYTHONPATH}:/path/cool/python/package/"
export PYTHONPATH

These checks the settings :

import os
import sys
print(sys.path)
print(os.environ.get('PYTHONPATH', ''))

-hth
Gys
--
https://mail.python.org/mailman/listinfo/python-list


Re: How do I read .csv files

2021-03-16 Thread Gys

On 3/12/21 11:28 AM, Johann Klammer wrote:

Specifically ones with quoted strings. I'll have whitespace in
there and possibly escaped quotechars.
maybe newlines too.
Which means that pyparsing commaSeparatedList.parseString(line) won't work.

I also like to edit them for visual alignment, so there'll
be whitespaces outside the strings(more than one)
...therefore, csv.DictReader() won't work.

I'd like them read into a dict or something..


Hi Johann Klammer,
I use Pandas for handling *.csv files

pandas documentation :

<https://pandas.pydata.org/pandas-docs/stable/index.html>

Hands on example :

<https://chrisalbon.com/python/data_wrangling/pandas_dataframe_importing_csv/>

-hth
Gys

--
https://mail.python.org/mailman/listinfo/python-list


Re: Convert a scientific notation to decimal number, and still keeping the data format as float64

2019-10-18 Thread Gys

On 10/18/19 10:35 AM, doganad...@gmail.com wrote:


Here is my question:


I am using the numpy.std formula to calculate the standart deviation. However, 
the result comes as a number in scientific notation.
Therefore I am asking, How to convert a scientific notation to decimal number, 
and still keep the data format as float64 ?

Or is there any workaround to get the initial standart deviation result as a 
decimal number?


Here is my code:

stdev=numpy.std(dataset)
print(stdev)
 Result: 4.449e-05


print(stdev.dtype)
 Result: float64


Solutions such as this:

stdev=format(stdev, '.10f')
converts the data into a string object! which I don't want.


Expected result: I am willing to have a result as a decimal number in a float64 
format.

System: (Python 3.7.4 running on Win10)


Regards,



Hi, doganad...@gmail.com

why don't you use

print("{0:10.5f}".format(x))

The only thing you want is a specific form of the human readable 
representation of the number. For this it is not necessary the convert 
the  *number* itself definitely to a string. You only have to make a 
temp copy of x for printing purposes.


Linux Mint Tara in Spyder(Python 3.6) :

x=4.449e-05

print(x)
4.449e-05

print("{0:8.5f}".format(x))
 0.5

print(x)
4.9999449e-05

hth
Gys
--
https://mail.python.org/mailman/listinfo/python-list


Re: Books for Python 3.7

2019-07-15 Thread Gys

On 7/12/19 4:36 PM, mok...@gmail.com wrote:

Can anyone help me.
New to Python.
Installed version 3.7
I purchased the "Python for Dummies" book But this book was written for an 
older version of Python.
All the examples and samples don't work with version 3.7
Can anyone direct me to which is the latest book to buy to properly learn 
Python.
Thanks


Hi Richy M,
I'm in somewhat the same situation. I'm retired now at 73. Used Fortran 
on IBM, Vax, PDP. Visual Basic on Windows for Work Groups to Windows 10 
and changed to Linux Mint about 1 year ago. Started Python about that time.


I quickly learned that Python is more a ecosystem than a programming 
language my advice would be to search what ecosystem you want.


I always use a pet project, like suggested by Andrew Z, when I start 
something new. My pet project is Geo Information Systems or Gis for 
short. So I have Python 3 and the Python Gis tools. I make long cycle 
tours with OsmAnd on a Samsung Galaxy for navigation and record the Gpx 
Tracks. I use Python 3 for analysing the tracks. I use Pandas which let 
me use Excel like Data Sheets in Python :

https://pandas.pydata.org/pandas-docs/stable/index.html
If you also have MathPlot you have a serious competitor for MathLab. 
Pandas also includes Numpy for better manipulation of arrays. If you 
have a look at Anaconda

https://www.anaconda.com/distribution/
you can download the suite in one go. I used the official Linux Mint 
repository to download the things I wanted. I think you will greatly 
benefit from a IDE I use Spider (also in the Anaconda suite) :

https://www.spyder-ide.org/
but there are several others. If you want to create a GUI in your 
programs than Quantum seems a great Idea. I use PyQt5 which is the 
Python 3 version of Quantum version 5.


I also would like to have a good book, but have not yet decided which 
one. There is a 50$ book on learning Python; the language reference (?) 
There is a 50$ book for learning PyQt5 programming of a GUI. There is a 
50$ book on using Python in Pandas for analysing tabular data.


In the meantime I use Gitlab for finding code snippets. I use these 
beginner guides :


https://www.python.org/doc/
https://www.tutorialspoint.com/python3/
https://overiq.com/python-101/
https://www.pythonforbeginners.com/
https://www.programiz.com/python-programming/tutorial

hth
Gys

--
https://mail.python.org/mailman/listinfo/python-list