Newest questions tagged python - Stack Overflow

most recent 30 from

Django password validator for multiple symbols



Creating password requirements for a user in Django using:


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?


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 Because the network has many different dimension of filters.

merge 2 csv files by columns error related to strings?


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 = np.array(temp_data)

however the error said:

    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



I have a simple df:

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

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\", line 13, in <module>
  File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\", line 2878, in __getitem__
    return self._get_item_cache(key)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\", line 3541, in _get_item_cache
    values = self._mgr.iget(loc)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\internals\", 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?


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!