<jupyter_start><jupyter_text>fill nan<jupyter_code>import sys
import os
import json
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
# from pyspark.sql import SparkSession
# from pyspark.sql import SQLContext
import seaborn as sns
%matplotlib inline
import matplotlib
matplotlib.rcParams['font.sans-serif'] = 'WenQuanYi Micro Hei'
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
xlsx = pd.ExcelFile('/cbs/jupyter-files/pandas/demo1.xlsx')

bill = pd.read_excel(xlsx, 0) #总账
bill.head(10)
bill.fillna(method='pad')  ##向前填充
bill.fillna(method='backfill')  #向后填充不空值
df2['name'].fillna('missing') #填充一个列<jupyter_output><empty_output><jupyter_text>Filling with a PandasObject<jupyter_code>dff = pd.DataFrame(np.random.randn(7,3), columns=list('ABC'))
dff.iloc[3:5,0] = np.nan
dff.iloc[4:6,1] = np.nan
dff.iloc[5:8,2] = np.nan
dff
dff.fillna(dff.mean())
dff1=dff.fillna(dff.mean()['B':'C'])
dff1<jupyter_output><empty_output><jupyter_text>Dropping axis labels with missing data: dropna<jupyter_code>dff1.A=np.NAN
dff1
 dff1.dropna(axis=0) ##删除包含空行
dff1.dropna(axis=1)  ##删除包含空列<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1404399323181049, 'fraction_numerical': 0.02030456852791878, 'mean_word_length': 7.635036496350365, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '384314', 'license': 'MIT', 'n_tokens_mistral': 528, 'n_tokens_neox': 532, 'n_words': 84, 'path': 'pandas/fill-nan-drop.ipynb', 'repo_name': 'weisong82/python_ecology_learning', 'size': '1182'}