How can I split dataframe with blank spaces

116
March 29, 2022, at 10:10 PM
import pandas
import numpy
names = ['a', 'b', 'c']
df = pandas.DataFrame([1, 2, 3, numpy.nan, numpy.nan, 4, 5, 6, numpy.nan, numpy.nan, 7, 8, 9])

For the above one, how will the condition change? Can someone please explain? how can I get this,

df1 = 
     0
0  1.0
1  2.0
2  3.0
df2 =
     0
4  4.0
5  5.0
6  6.0
df3 = 
      0
8   7.0
9   8.0
10  9.0
Answer 1

You can generate a temporary column, remove NaNs, and group by the temporary column:

dataframes = {f'df{idx+1}': d for idx, (_, d) in enumerate(df.dropna().groupby(df.assign(cond=df.isna().cumsum()).dropna()['cond']))}

Output:

>>> dataframes
{'df1':      0
 0  1.0
 1  2.0
 2  3.0,
 'df2':      0
 5  4.0
 6  5.0
 7  6.0,
 'df3':       0
 10  7.0
 11  8.0
 12  9.0}
 
>>> dataframes['df1']
     0
0  1.0
1  2.0
2  3.0
>>> dataframes['df2']
     0
5  4.0
6  5.0
7  6.0
>>> dataframes['df3']
      0
10  7.0
11  8.0
12  9.0
Rent Charter Buses Company
READ ALSO
copy mysqldb tables into a different database by looking for only changes using python (trying to do in batch process)

copy mysqldb tables into a different database by looking for only changes using python (trying to do in batch process)

i need to look in to the database tables and copy the whole table and send it to destination location dbIt should only update the changes on the destination

127
Slicing Error when using custom cost function in Keras

Slicing Error when using custom cost function in Keras

I have example dataThis data is used to set the predictor (x) and response (y) variables:

142
DatetimeIndex.get_loc is deprecated

DatetimeIndex.get_loc is deprecated

I updated Pandas to 14

163
Can opencv be used with apple’s coremL (Neural Engine)?

Can opencv be used with apple’s coremL (Neural Engine)?

I have a simple opencv script in python running on an M1 Mac to detect objects withIs it possible to use Apple’s coreML to accelerate OpenCV? I've installed TensorFlow-metal (using https://developer

133