You are right, such errors mostly caused by NaN representing empty cells. It is common to filter out such data, before applying your further operations, using this idiom on your dataframe df:
df_new = df[df['ColumnName'].notnull()]
Alternatively, it may be more handy to use fillna()
method to impute (to replace) null
values with something default. E.g. all null
or NaN
‘s can be replaced with the average value for its column
housing['LotArea'] = housing['LotArea'].fillna(housing.mean()['LotArea'])
or can be replaced with a value like empty string “” or another default value
housing['GarageCond']=housing['GarageCond'].fillna("")
Related Posts:
- TypeError: list indices must be integers or slices, not str
- Writing a pandas DataFrame to CSV file
- Writing a pandas DataFrame to CSV file
- How can I split and parse a string in Python?
- How do I parse a string to a float or int?
- How to parse data in JSON format?
- IndexError: too many indices for array
- How to replace NaN values by Zeroes in a column of a Pandas Dataframe?
- ValueError : I/O operation on closed file
- Pandas: ValueError: cannot convert float NaN to integer
- csv.Error: iterator should return strings, not bytes
- Python – Reading and writing csv files with utf-8 encoding
- convert nan value to zero
- Python Error io.UnsupportedOperation: not readable
- load csv into 2D matrix with numpy for plotting
- Dump a NumPy array into a csv file
- (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape
- How to load a tsv file into a Pandas DataFrame?
- Python/Json:Expecting property name enclosed in double quotes
- Difference between writerow() and writerows() methods of Python csv module
- Create a .csv file with values from a Python list
- Convert XML to CSV file
- TypeError: list indices must be integers or slices, not str
- Convert from CSV to array in Python
- ValueError: cannot index with vector containing NA / NaN values
- (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape
- Creating a dictionary from a csv file?
- Python import csv to list
- ValueError: x and y must be the same size
- OSError: Initializing from file failed on csv in Pandas
- append new row to old csv file python
- pandas DataFrame: replace nan values with average of columns
- Writing a dictionary to a csv file with one line for every ‘key: value’
- Python CSV error: line contains NULL byte
- Removing nan values from an array
- Python CSV Error: sequence expected
- How to add pandas data to an existing csv file?
- convert csv file to list of dictionaries
- _csv.Error: field larger than field limit (131072)
- CSV new-line character seen in unquoted field error
- Writing Python lists to columns in csv
- Python code to remove HTML tags from a string
- Error in Reading a csv file in pandas[CParserError: Error tokenizing data. C error: Buffer overflow caught – possible malformed input file.]
- How to read a CSV file from a URL with Python?
- How to import a csv-file into a data array?
- Why am I seeing “TypeError: string indices must be integers”?
- TypeError: only integer scalar arrays can be converted to a scalar index with 1D numpy indices array
- How to emulate a do-while loop?
- How to prettyprint a JSON file?
- How to install pip with Python 3?
- pip not recognised as an internal or external command
- Import Error: No module named numpy
- bash: pip: command not found
- Function for Factorial in Python
- TypeError: a bytes-like object is required, not ‘str’ when writing to a file in Python3
- Local variable referenced before assignment?
- Clickable link inside message discord.py
- DataFrame constructor not properly called! error
- OSError: [WinError 193] %1 is not a valid Win32 application
- How to download a file over HTTP?
- “ImportError: no module named ‘requests'” after installing with pip
- Append integer to beginning of list in Python
- Most efficient way to map function over numpy array
- List comprehension on a nested list?
- Get total of Pandas column
- How do you read from stdin?
- Union of two lists in Python
- Type error: cannot convert the series to
- How to deep copy a list?
- Pandas – DataFrame object is not callable
- Start with pyglet or pygame?
- Django 2.1.3 Error: __init__() takes 1 positional argument but 2 were given
- Python error load JSON code of google API
- Convert categorical data in pandas dataframe
- pandas create new column based on values from other columns / apply a function of multiple columns, row-wise
- Truncate to three decimals in Python
- Scatter plot colorbar – Matplotlib
- “SyntaxError: non-keyword arg after keyword arg” Error in Python when using requests.post()
- Flask Error: “Method Not Allowed The method is not allowed for the requested URL”
- Pandas error “Can only use .str accessor with string values”
- matplotlib: how to draw a rectangle on image
- How to install PyGame on Python 3.4?
- ImportError: No module named ‘cv2’ Python3
- bbox_to_anchor and loc in matplotlib
- Python 3.5.1 urllib has no attribute request
- Rotating a two-dimensional array in Python
- TypeError: sequence item 0: expected string, int found
- Why am I getting this unexpected keyword argument TypeError?
- Create numpy matrix filled with NaNs
- python pandas remove duplicate columns
- What is the difference between __str__ and __repr__?
- cmake error ‘the source does not appear to contain CMakeLists.txt’
- ubuntu /usr/bin/env: python: No such file or directory
- How to completely uninstall python 2.7.13 on Ubuntu 16.04
- Calculate weighted average using a pandas/dataframe
- Telling Python to save a .txt file to a certain directory on Windows and Mac
- Write a program that asks the user to enter five test scores. Correspond it to a letter grade
- Simplify Chained Comparison
- How to get POSTed JSON in Flask?
- How to fix SSL issue SSL_CTX_use_certificate : ca md too weak on Python Zeep