python

Python Pandas - use Multiple Character Delimiter when writing to_csv

本小妞迷上赌 提交于 2021-02-20 18:48:20
问题 It appears that the pandas to_csv function only allows single character delimiters/separators. Is there some way to allow for a string of characters to be used like, "::" or "%%" instead? I tried: df.to_csv(local_file, sep = '::', header=None, index=False) and getting: TypeError: "delimiter" must be a 1-character string 回答1: Use numpy-savetxt Ex: np.savetxt(file.csv, np.char.decode(chunk_data.values.astype(np.bytes_), 'UTF-8'), delimiter='~|', fmt='%s',encoding=None) np.savetxt(file.dat,

Set and verify SSL/TLS version used in Python MySQL connection

余生颓废 提交于 2021-02-20 18:48:03
问题 How can I tell the Python MySQL connector which SSL/TLS protocol to use? Either specific (e.g. TLS1.2) or minimum. How can I check which protocol is used on an established connection? I've got an app that uses mysql-connector-python (8.0.18). I connect something like this: cnx = mysql.connector.connect(user='x', password='y', host='localhost', database='xyz') Usually this gives me no trouble, but recently on a web hosting providers server it stopped working. The error I'm now getting is along

Python Pandas - use Multiple Character Delimiter when writing to_csv

核能气质少年 提交于 2021-02-20 18:47:47
问题 It appears that the pandas to_csv function only allows single character delimiters/separators. Is there some way to allow for a string of characters to be used like, "::" or "%%" instead? I tried: df.to_csv(local_file, sep = '::', header=None, index=False) and getting: TypeError: "delimiter" must be a 1-character string 回答1: Use numpy-savetxt Ex: np.savetxt(file.csv, np.char.decode(chunk_data.values.astype(np.bytes_), 'UTF-8'), delimiter='~|', fmt='%s',encoding=None) np.savetxt(file.dat,

Force TkInter Scale slider to snap to mouse

∥☆過路亽.° 提交于 2021-02-20 18:47:35
问题 When a GUI has a TkInter Scale and they click somewhere on the scale, the default behavior seems to be to slide the slider along the Scale in the direction towards the mouse (and then unexpectedly past their mouse). What I'd want instead is to have the slider always jump to and stay attached to the user's mouse point while they're clicking anywhere on the slider. If they click to a particular point on the Scale, the slider should jump directly to that point. I have some code below which

Tensorflow compatibility with Keras

淺唱寂寞╮ 提交于 2021-02-20 18:47:00
问题 I am using Python 3.6 and Tensorflow 2.0, and have some Keras codes: import keras from keras.models import Sequential from keras.layers import Dense model = Sequential() model.add(Dense(1)) model.compile(optimizer='adam',loss='mean_squared_error',metrics=['accuracy']) However I got the error: "Keras requires TensorFlow 2.2 or higher. Install TensorFlow via pip install tensorflow " when trying to run it. I checked on https://keras.io/, it says Keras was built on Tensorflow 2.0. So I am

Mutable Default Method Arguments In Python [duplicate]

青春壹個敷衍的年華 提交于 2021-02-20 18:46:41
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: “Least Astonishment” in Python: The Mutable Default Argument I am using the Python IDE PyCharm and something that is have by default is it will showing warning when I have a mutbale type as a default value. For example, when I have this: def status(self, options=[]): PyCharm wants it to looks like: def status(self, options=None): if not options: options = [] My question is whether or not this is a standard way

Python Pandas - use Multiple Character Delimiter when writing to_csv

∥☆過路亽.° 提交于 2021-02-20 18:46:10
问题 It appears that the pandas to_csv function only allows single character delimiters/separators. Is there some way to allow for a string of characters to be used like, "::" or "%%" instead? I tried: df.to_csv(local_file, sep = '::', header=None, index=False) and getting: TypeError: "delimiter" must be a 1-character string 回答1: Use numpy-savetxt Ex: np.savetxt(file.csv, np.char.decode(chunk_data.values.astype(np.bytes_), 'UTF-8'), delimiter='~|', fmt='%s',encoding=None) np.savetxt(file.dat,

WindowsError: [Error 127] The specified procedure could not be found

六眼飞鱼酱① 提交于 2021-02-20 18:45:46
问题 What does this error mean? I have trouble googling any docs. The code worked fine and suddenly broke after restarting windows. I looked in the process monitor and the DLL is found and accessed without any permission errors File "c:\Python27\lib\ctypes\__init__.py", line 435, in __getattr__ dll = self._dlltype(name) File "c:\Python27\lib\ctypes\__init__.py", line 365, in __init__ self._handle = _dlopen(self._name, mode) WindowsError: [Error 127] The specified procedure could not be found 回答1:

WindowsError: [Error 127] The specified procedure could not be found

谁说我不能喝 提交于 2021-02-20 18:44:22
问题 What does this error mean? I have trouble googling any docs. The code worked fine and suddenly broke after restarting windows. I looked in the process monitor and the DLL is found and accessed without any permission errors File "c:\Python27\lib\ctypes\__init__.py", line 435, in __getattr__ dll = self._dlltype(name) File "c:\Python27\lib\ctypes\__init__.py", line 365, in __init__ self._handle = _dlopen(self._name, mode) WindowsError: [Error 127] The specified procedure could not be found 回答1:

pandas merge with MultiIndex, when only one level of index is to be used as key

不问归期 提交于 2021-02-20 17:56:35
问题 I have a data frame called df1 with a 2-level MultiIndex (levels: '_Date' and _'ItemId'). There are multiple instances of each value of '_ItemId', like this: _SomeOtherLabel _Date _ItemId 2014-10-05 6588921 AA 6592520 AB 6836143 BA 2014-10-11 6588921 CA 6592520 CB 6836143 DA I have a second data frame called df2 with '_ItemId' used as a key (not the index). In this df, there is only one occurrence of each value of _ItemId: _ItemId _Cat 0 6588921 6_1 1 6592520 6_1 2 6836143 7_1 I want to