Hello Python Community
I am trying to process data from a pandas data frame that includes cell wrap as in the dataframe below.
Note that the last names are wrapping into the row below.
I tried iterating through the dataframe using:
for row in df.itertuples(index=True):
and updating the cell using:
df.Last[ii-1] = updateCell
and deleting the old row using:
df.drop([df.index[ii]],inplace=True)
But I encountered warnings like this:
A value is trying to be set on a copy of a slice from a DataFrame
and further problems with indexes after the drop.
What is the best approach for this problem?
Barry
import numpy as np
# initialize list of lists
data = [['Barney', 'Rubble', 25],
['Fred','Flintstone', 25],
['Wilma','Slaghoople ',22],
[ np.nan,'Flintstone', np.nan],
[ 'Betty', 'McBricker', 21],
[ np.nan, 'Rubble', np.nan]]
# Create the pandas DataFrame
df = pd.DataFrame(data, columns = ['First', 'Last', 'Age']) ```