Drop a specific row in Pandas

df = pd.DataFrame([[‘Jhon’,15,’A’],[‘Anna’,19,’B’],[‘Paul’,25,’D’]]) df. columns = [‘Name’,’Age’,’Grade’] df Out[472]: Name Age Grade 0 Jhon 15 A 1 Anna 19 B 2 Paul 25 D You can get the index of your row: i = df[((df.Name == ‘jhon’) &( df.Age == 15) & (df.Grade == ‘A’))].index and then drop it: df.drop(i) Out[474]: Name Age Grade 1 … Read more

How to drop a row whose particular column is empty/NaN?

Use dropna with parameter subset for specify column for check NaNs: data = data.dropna(subset=[‘sms’]) print (data) id city department sms category 1 2 lhr revenue good 1 Another solution with boolean indexing and notnull: data = data[data[‘sms’].notnull()] print (data) id city department sms category 1 2 lhr revenue good 1 Alternative with query: print (data.query(“sms … Read more

How to convert single-row pandas data frame to series?

You can transpose the single-row dataframe (which still results in a dataframe) and then squeeze the results into a series (the inverse of to_frame). df = pd.DataFrame([list(range(5))], columns=[“a{}”.format(i) for i in range(5)]) >>> df.squeeze(axis=0) a0 0 a1 1 a2 2 a3 3 a4 4 Name: 0, dtype: int64 Note: To accommodate the point raised by … Read more

How to remove timezone from a Timestamp column in pandas

The column must be a datetime dtype, for example after using pd.to_datetime. Then, you can use tz_localize to change the time zone, a naive timestamp corresponds to time zone None: testdata[‘time’].dt.tz_localize(None) Unless the column is an index (DatetimeIndex), the .dt accessor must be used to access pandas datetime functions.

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