Filling missing values using forward and backward fill in pandas dataframe (ffill and bfill)

You can use ffill and bfill if need replace NaN values forward and backward filling: print (df) A B DateTime 01-01-2017 03:27 NaN NaN 01-01-2017 03:28 NaN NaN 01-01-2017 03:29 0.181277 -0.178836 01-01-2017 03:30 0.186923 -0.183261 01-01-2017 03:31 NaN NaN 01-01-2017 03:32 NaN NaN 01-01-2017 03:33 0.181277 -0.178836 data = df.ffill().bfill() print (data) A B … Read more

python pandas extract unique dates from time series

If you have a Series like: In [116]: df[“Date”] Out[116]: 0 2012-10-08 07:12:22 1 2012-10-08 09:14:00 2 2012-10-08 09:15:00 3 2012-10-08 09:15:01 4 2012-10-08 09:15:01.500000 5 2012-10-08 09:15:02 6 2012-10-08 09:15:02.500000 7 2012-10-10 07:19:30 8 2012-10-10 09:14:00 9 2012-10-10 09:15:00 10 2012-10-10 09:15:01 11 2012-10-10 09:15:01.500000 12 2012-10-10 09:15:02 Name: Date where each object is … Read more

How to remove square bracket from pandas dataframe

If values in column value have type list, use: df[‘value’] = df[‘value’].str[0] Or: df[‘value’] = df[‘value’].str.get(0) Docs. Sample: df = pd.DataFrame({‘value’:[[63],[65],[64]]}) print (df) value 0 [63] 1 [65] 2 [64] #check type if index 0 exist print (type(df.loc[0, ‘value’])) <class ‘list’> #check type generally, index can be `DatetimeIndex`, `FloatIndex`… print (type(df.loc[df.index[0], ‘value’])) <class ‘list’> df[‘value’] … Read more

How to write a Pandas DataFrame to Django model

I’m just going through the same exercise at the moment. The approach I’ve taken is to create a list of new objects from the DataFrame and then bulk create them: bulk_create(objs, batch_size=None) This method inserts the provided list of objects into the database in an efficient manner (generally only 1 query, no matter how many … Read more

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