rows

pandas – change df.index from float64 to unicode or string

pandas – change df.index from float64 to unicode or string Question: I want to change a dataframes’ index (rows) from float64 to string or unicode. I thought this would work but apparently not: #check type type(df.index) ‘pandas.core.index.Float64Index’ #change type to unicode if not isinstance(df.index, unicode): df.index = df.index.astype(unicode) error message: TypeError: Setting <class ‘pandas.core.index.Float64Index’> dtype …

Total answers: 3

Compare Python Pandas DataFrames for matching rows

Compare Python Pandas DataFrames for matching rows Question: I have this DataFrame (df1) in Pandas: df1 = pd.DataFrame(np.random.rand(10,4),columns=list(‘ABCD’)) print df1 A B C D 0.860379 0.726956 0.394529 0.833217 0.014180 0.813828 0.559891 0.339647 0.782838 0.698993 0.551252 0.361034 0.833370 0.982056 0.741821 0.006864 0.855955 0.546562 0.270425 0.136006 0.491538 0.445024 0.971603 0.690001 0.911696 0.065338 0.796946 0.853456 0.744923 0.545661 0.492739 …

Total answers: 2

Numpy – add row to array

Numpy – add row to array Question: How does one add rows to a numpy array? I have an array A: A = array([[0, 1, 2], [0, 2, 0]]) I wish to add rows to this array from another array X if the first element of each row in X meets a specific condition. Numpy …

Total answers: 10

Python: Number of rows affected by cursor.execute("SELECT …)

Python: Number of rows affected by cursor.execute("SELECT …) Question: How can I access the number of rows affected by: cursor.execute(“SELECT COUNT(*) from result where server_state=’2′ AND name LIKE ‘”+digest+”_”+charset+”_%'”) Asked By: Tie-fighter || Source Answers: From PEP 249, which is usually implemented by Python database APIs: Cursor Objects should respond to the following methods and …

Total answers: 6