Python | pandas.to_numeric method Last Updated : 17 Dec, 2018 Comments Improve Suggest changes Like Article Like Report Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. pandas.to_numeric() is one of the general functions in Pandas which is used to convert argument to a numeric type. Syntax: pandas.to_numeric(arg, errors='raise', downcast=None) Parameters: arg : list, tuple, 1-d array, or Series errors : {‘ignore’, ‘raise’, ‘coerce’}, default ‘raise’ -> If ‘raise’, then invalid parsing will raise an exception -> If ‘coerce’, then invalid parsing will be set as NaN -> If ‘ignore’, then invalid parsing will return the input downcast : [default None] If not None, and if the data has been successfully cast to a numerical dtype downcast that resulting data to the smallest numerical dtype possible according to the following rules: -> ‘integer’ or ‘signed’: smallest signed int dtype (min.: np.int8) -> ‘unsigned’: smallest unsigned int dtype (min.: np.uint8) -> ‘float’: smallest float dtype (min.: np.float32) Returns: numeric if parsing succeeded. Note that return type depends on input. Series if Series, otherwise ndarray. Code #1: Observe this dataset first. We'll use 'Numbers' column of this data in order to make Series and then do the operation. Python3 1== # importing pandas module import pandas as pd # making data frame df = pd.read_csv("https://media.geeksforgeeks.org/wp-content/uploads/nba.csv") df.head(10) Calling Series constructor on Number column and then selecting first 10 rows. Python3 1== # importing pandas module import pandas as pd # making data frame df = pd.read_csv("nba.csv") # get first ten 'numbers' ser = pd.Series(df['Number']).head(10) ser Output: Using pd.to_numeric() method. Observe that by using downcast='signed', all the values will be casted to integer. Python3 1== pd.to_numeric(ser, downcast ='signed') Output: Code #2: Using errors='ignore'. It will ignore all non-numeric values. Python3 1== # importing pandas module import pandas as pd # get first ten 'numbers' ser = pd.Series(['Geeks', 11, 22.7, 33]) pd.to_numeric(ser, errors ='ignore') Output: Code #3: Using errors='coerce'. It will replace all non-numeric values with NaN. Python3 1== # importing pandas module import pandas as pd # get first ten 'numbers' ser = pd.Series(['Geeks', 11, 22.7, 33]) pd.to_numeric(ser, errors ='coerce') Output: Comment More infoAdvertise with us Next Article Python | pandas.to_numeric method S Shivam_k Follow Improve Article Tags : Python Python-pandas Python pandas-general-functions Practice Tags : python Similar Reads Pandas dataframe.sum() DataFrame.sum() function in Pandas allows users to compute the sum of values along a specified axis. It can be used to sum values along either the index (rows) or columns, while also providing flexibility in handling missing (NaN) values. Example:Pythonimport pandas as pd data = { 'A': [1, 2, 3], 'B 4 min read Pandas DataFrame mean() Method Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas DataFrame mean() Pandas dataframe.mean() function returns the mean of the value 2 min read Python | Pandas dataframe.median() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas dataframe.median() function return the median of the values for the requested a 2 min read Python | Pandas Series.std() Pandas series is a One-dimensional ndarray with axis labels. The labels need not be unique but must be a hashable type. The object supports both integer- and label-based indexing and provides a host of methods for performing operations involving the index. Pandas Series.std() function return sample 2 min read Apply function to every row in a Pandas DataFrame Python is a great language for performing data analysis tasks. It provides a huge amount of Classes and functions which help in analyzing and manipulating data more easily. In this article, we will see how we can apply a function to every row in a Pandas Dataframe. Apply Function to Every Row in a P 7 min read Joining two Pandas DataFrames using merge() The merge() function is designed to merge two DataFrames based on one or more columns with matching values. The basic idea is to identify columns that contain common data between the DataFrames and use them to align rows. Let's understand the process of joining two pandas DataFrames using merge(), e 4 min read Python | Pandas DataFrame.astype() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier. DataFrame.astype() method is used to cast a pandas object to a specified dtype.astype( 4 min read Python | Pandas DataFrame.set_index() Pandas DataFrame.set_index() method sets one or more columns as the index of a DataFrame. It can accept single or multiple column names and is useful for modifying or adding new indices to your DataFrame. By doing so, you can enhance data retrieval, indexing, and merging tasks.Syntax: DataFrame.set_ 3 min read Pandas DataFrame.reset_index() In Pandas, reset_index() method is used to reset the index of a DataFrame. By default, it creates a new integer-based index starting from 0, making the DataFrame easier to work with in various scenarios, especially after performing operations like filtering, grouping or multi-level indexing. Example 3 min read Python | Pandas Dataframe.at[ ] Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas at[] is used to return data in a dataframe at the passed location. The passed l 2 min read Like