Select non-null rows from a specific column in a DataFrame and take a sub-selection of other columns

You can pass a boolean mask to your df based on notnull() of ‘Survive’ column and select the cols of interest: In [2]: # make some data df = pd.DataFrame(np.random.randn(5,7), columns= [‘Survive’, ‘Age’,’Fare’, ‘Group_Size’,’deck’, ‘Pclass’, ‘Title’ ]) df[‘Survive’].iloc[2] = np.NaN df Out[2]: Survive Age Fare Group_Size deck Pclass Title 0 1.174206 -0.056846 0.454437 0.496695 1.401509 … Read more

In JDBC, why do parameter indexes for prepared statements begin at 1 instead of 0?

Historically, databases have used 1-based indexing for bound parameters. This probably reflects the origins of relational databases in set theory and mathematics, which index elements starting with one, and use zero to represent a null or empty set. In shell scripts and regular expressions, the zero index usually means something “special”. For example, in the … Read more

Change a Primary Key from Nonclustered to Clustered

1) Drop the existing clustered index first (IX_TableX_FieldB): DROP INDEX TableX.IX_TableX_FieldB 2) Create a (temporary) UNIQUE constraint on the unique fields referenced in the primary key ALTER TABLE TableX ADD CONSTRAINT UQ_TableX UNIQUE(FieldA) 3) Drop the PRIMARY KEY ALTER TABLE TableX DROP CONSTRAINT PK_TableX 4) Recreate the PRIMARY KEY as CLUSTERED ALTER TABLE TableX ADD … Read more

Find the index of the n’th item in a list

The answer from @Taymon using list.index was great. FWIW, here’s a functional approach using the itertools module. It works with any iterable input, not just lists: >>> from itertools import compress, count, imap, islice >>> from functools import partial >>> from operator import eq >>> def nth_item(n, item, iterable): indicies = compress(count(), imap(partial(eq, item), iterable)) … Read more

How do I subtract the previous row from the current row in a pandas dataframe and apply it to every row; without using a loop?

you can use pct_change() or/and diff() methods Demo: In [138]: df.Close.pct_change() * 100 Out[138]: 0 NaN 1 0.469484 2 0.467290 3 -0.930233 4 0.469484 5 0.467290 6 0.000000 7 -3.255814 8 -3.365385 9 -0.497512 Name: Close, dtype: float64 In [139]: df.Close.diff() Out[139]: 0 NaN 1 0.125 2 0.125 3 -0.250 4 0.125 5 0.125 6 … Read more

MySQL varchar index length

Sept 2021 edit: I’ve been using MySQL 8.0 for a couple years now, so here’s some updated info. The MySQL manual now has a very informative page regarding conversion between utf8mb3 (currently also known as utf8) and utf8mb4. utf8mb3 is deprecated and will be removed eventually; and when it is removed, its current alias, utf8, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)