Challenge
Try to apply the aquired knowledge to fix the first problematic column.
Завдання
Swipe to start coding
You are given the Statvillage dataset. You need to convert the 'totinch'
column' values to float
type by replacing commas by dots. Follow the next steps:
- Select the
'totinch'
column. - Apply the
str
accessor to the chosen column. - Replace the
,
symbols in the column values with the.
. - Convert type to
float
.
Рішення
99
1
2
3
4
5
6
7
8
9
10
# Importing the library
import pandas as pd
# Reading the data
df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/f2947b09-5f0d-4ad9-992f-ec0b87cd4b3f/data.csv')
# Perform a replacement and convert column type
df['totinch'] = df.totinch.str.replace(',', '.').astype(float)
# Testing
print(df.totinch)
Все було зрозуміло?
Дякуємо за ваш відгук!
Секція 1. Розділ 5
99
1
2
3
4
5
6
7
8
9
10
# Importing the library
import pandas as pd
# Reading the data
df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/f2947b09-5f0d-4ad9-992f-ec0b87cd4b3f/data.csv')
# Perform a replacement and convert column type
df['totinch'] = ___.___.___.___(___, ___).___(___)
# Testing
print(df.totinch)
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат