Newest questions tagged python - Stack Overflow

https://stackoverflow.com/questions/tagged/?tagnames=python&sort=newest

most recent 30 from stackoverflow.com

Django password validator for multiple symbols

2021-04-1902:05

andredms

Creating password requirements for a user in Django using:

django.contrib.auth.password_validation.UserAttributeSimilarityValidator
django.contrib.auth.password_validation.MinimumLengthValidator
django.contrib.auth.password_validation.CommonPasswordValidator
django.contrib.auth.password_validation.NumericPasswordValidator

However, when I use the password $a1ABCD%#@ it gives me the error message:

At least one special character (punctuation, brackets, quotes, etc.), at least one lowercase character, at least one uppercase character, at least one digit, at least 8 chars.

$a1ABCD@ seems to work though. Any ideas?

In tensorfow, How can I set specific parameters to neurl network from a small scale network, such as CNN?

2021-04-1902:04

xuguang hu

In the training process, I want to change the parameters of neural network from a small scale network.

For example, the filter of smale scale network is 3~3, the training neural network is 9~9. I want the filter value of the training neural network come from the the filter of smale scale network.

I use "tf.trainable_variables(scope='CNN')" and "tf.tile" to expand the dimension, and then "tf.assign" is used to achieve this target. However, it can apply in the change of single value.

How can I change the all values in the same order:sess.run()? Because the network has many different dimension of filters.

merge 2 csv files by columns error related to strings?

2021-04-1902:01

chen abien

I am trying to merge 2 csv files by column.
my both csv file has a format as such and they both ends with '_4.csv' as filename:

    0-10       ,83.72,66.76,86.98
    11-20      ,15.01,31.12,12.04
    21-30      ,1.14,2.05,0.94
    31-40      ,0.13,0.07,0.03
    41-50      ,0.0,0.0,0.0
    51-60      ,0.0,0.0,0.0
    over 60    ,0.0,0.0,0.0
    UHF case  ,0.0,0.0,0.0

my code:

    #combine 2 csv into 1 by columns
    files_in_dir = [f for f in os.listdir(os.getcwd()) if f.endswith('_4.csv')]
    temp_data = []
    for filenames in files_in_dir:
        temp_data.append(np.loadtxt(filenames,dtype='str'))
    temp_data = np.array(temp_data)
    np.savetxt('_mix.csv',temp_data.transpose(),fmt='%s',delimiter=',')

however the error said:

    temp_data.append(np.loadtxt(filenames,dtype='str'))
    for x in read_data(_loadtxt_chunksize):
    raise ValueError("Wrong number of columns at line %d"
    ValueError: Wrong number of columns at line 2

not sure if it is related to the first column being strings rather than values.
Does anyone know how to fix it? much appreciation

Type error: only integer scalar arrays can be converted to a scalar index when doing .loc with pandas DataFrame

2021-04-1902:00

QuantyZxxxx

I have a simple df:

a = pd.DataFrame([[1,2,3,5,8],['jack','jeff',np.nan,np.nan,'tesla']])
    a.index = [['number','name']]
    a=a.T

and it looks like this:

  number   name
0      1   jack
1      2   jeff
2      3    NaN
3      5    NaN
4      8  tesla

When I am tring to do a .loc like a.loc[a['number']==5], I got this type error:

Traceback (most recent call last):
  File "c:\Users\Administrator\Documents\proj\test.py", line 13, in <module>
    a.loc[a['number']==5]
  File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\frame.py", line 2878, in __getitem__
    return self._get_item_cache(key)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\generic.py", line 3541, in _get_item_cache
    values = self._mgr.iget(loc)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\internals\managers.py", line 988, in iget
    block = self.blocks[self.blknos[i]]
TypeError: only integer scalar arrays can be converted to a scalar index

I searched this error and tried some solutions like using a.loc[np.array(a)['number']==5] or reinstall pandas and numpy or anaconda but they are not working.

My pandas version is 1.3 and numpy version is 1.19.2

How to match top and bottom x-axes in Python with Matplotlb?

2021-04-1902:00

Carmen Selva

I am trying to plot the energy consumption profile of an electric vehicle. I am using the elevation profile vs the horizontal distance the vehicle runs along a path. I want to add a second x-axis on top of the plot to represent by each chunk of distance, what the energy consumption value was at that precise location. This is what I have so far, but it's not precisely what I need: ELevation profile plot. I know this should be fairly simple as it is only adding a second x-axis that matches with the primary x-axis, but I have wasted an entire day trying to figure out unsuccessfully :( Any insights will be greatly appreciated. Thanks in advance!

<
1