you can see for example the column world, there are some blank box, how can I replace it with new value, and then continue append new value to the world column. I tried many ways but I couldn't do it.
you can see for example the column world, there are some blank box, how can I replace it with new value, and then continue append new value to the world column. I tried many ways but I couldn't do it.
You'd better tell us what you tried, not just "many things". Did you try this? You can copy all the values from the other columns which you don't need to change and only change the "world" column (a little work with indexes).
Export the excel file as csv (comma-separated values) file and read the file using pandas. Say, you csv file name is data.csv.
import numpy as np
import pandas as pd
df = pd.read_csv('data.csv')
df
Output:
To replace the NaN values in the world column:
df['world'] = df['world'].replace(np.nan, 'some country')
To replace the NaN values in the whole dataframe:
df = df.replace(np.nan, 'some value')
To replace inplace i.e., no need to reassign:
df.replace(np.nan, 'some value', inplace=True)
To append some other values in dataframe:
df2 = pd.DataFrame([[True, 'bob', 'canada', 'hi'], [False, 'marley', 'jamaica', np.nan]],
columns=['status', 'user', 'world', 'cat'])
df = df.append(df2)
After all these operations, the dataframe may look like this: