Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Poor Data Presentation | Preprocessing Data: Part I
Data Manipulation using pandas

book
Poor Data Presentation

One of the reasons that can cause types inconsistency may be poor data presentation. For instance, values of weight column may have also the measurment unit (like, 25kg, 14lb). In this case Python will understand these values as strings.

Let's see what is wrong with the values in the columns we considered to have wrong type.

# Importing the library
import pandas as pd

# Reading the file
df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/f2947b09-5f0d-4ad9-992f-ec0b87cd4b3f/data.csv')
# Output values of 'problematic' columns
print(df.loc[:,['totinch', 'morgh', 'valueh', 'grosrth', 'omphtotinch']])
1234567
# Importing the library import pandas as pd # Reading the file df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/f2947b09-5f0d-4ad9-992f-ec0b87cd4b3f/data.csv') # Output values of 'problematic' columns print(df.loc[:,['totinch', 'morgh', 'valueh', 'grosrth', 'omphtotinch']])
copy

We found the root of the problem. All the columns but 'totinch' use dots . as indicator for missing values, while values in the 'totinch' column use commas , as the decimal separator. This may happen due to data origin, for instance. This problem can be solved by replacing commas with dots, and converting to float type.

Note, if you try to convert existing values into numeric type, then the error ValueError will be raised.

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 3

Fragen Sie AI

expand
ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

some-alt