我正在尝试从包含拉丁文和中文字符的 csv 中删除所有中文字符。数据看起来像:
address lat
1 ?????, Zhangjiang, Pudong New District, 203718 31.204024
2 ??, 3057?, Jinke Road, Pudong, 201203, China 31.181804
Run Code Online (Sandbox Code Playgroud)
我需要它看起来像:
address lat
1 , Zhangjiang, Pudong New District, 203718 31.204024
2 , 3057, Jinke Road, Pudong, 201203, China 31.181804
Run Code Online (Sandbox Code Playgroud)
我尝试过df.replace(/[^\x00-\x7F]/g, ""),df.replace(/[\u{0080}-\u{FFFF}]/gu,"")但出现错误:
df1.replace([^\x00-\x7F],"");
^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)
需要帮忙!谢谢
我正在使用Kaggle的Titanic数据集(https://www.kaggle.com/c/titanic/data),我想使用sklearn.preprocessing中的LabelEncoder转换Sex,最初标记为'male'或'female '进'0'或'1'.我有以下四行代码,
import pandas as pd
from sklearn.preprocessing import LabelEncoder
df = pd.read_csv('titanic.csv')
df['Sex'] = LabelEncoder.fit_transform(df['Sex'])
Run Code Online (Sandbox Code Playgroud)
但是当我运行它时,我收到以下错误消息:
TypeError: fit_transform() missing 1 required positional argument: 'y'
Run Code Online (Sandbox Code Playgroud)
错误来自第4行,即
df['Sex'] = LabelEncoder.fit_transform(df['Sex'])
Run Code Online (Sandbox Code Playgroud)
我想知道这里出了什么问题.虽然我知道我也可以使用map进行转换,这可能更简单,但我仍然想知道我对LabelEncoder的使用有什么问题.
我想在当前年份和 2016 年之间随机选择一个月份。这是我目前非常幼稚的解决方案
from random import choice
def get_month():
return choice({'2018-06','2018-05','2018-04','2018-03'})
Run Code Online (Sandbox Code Playgroud)
很明显,这个集合在未来会变得太大,那么实现这一目标的更好方法是什么?
import math
def reportSphereVolume(r):
SphereVolume = ((4/3)*math.pi*((r)**3))
return SphereVolume
def reportSphereSurfaceArea(r):
SphereSurfaceArea = ((4)*math.pi((r)**2))
return SphereSurfaceArea
radius = int(input("What is the radius of the sphere? " ))
reportSphereVolume(radius)
reportSphereSurfaceArea(radius)
Run Code Online (Sandbox Code Playgroud)
执行时,我收到以下内容.
What is the radius of the sphere? 10
Traceback (most recent call last):
File "D:\Thonny\SphereAreaVolume.py", line 16, in <module>
reportSphereSurfaceArea(radius)
File "D:\Thonny\SphereAreaVolume.py", line 11, in reportSphereSurfaceArea
SphereSurfaceArea = ((4)*math.pi((r)**2))
TypeError: 'float' object is not callable
Run Code Online (Sandbox Code Playgroud)
我迷路了,我一直在看视频和阅读教科书,但我仍然无法解决.请帮忙.
MinMaxScaler和标准缩放器之间有什么区别.
MMS= MinMaxScaler(feature_range = (0, 1)) (用于Program1)
sc = StandardScaler() (在另一个程序中,他们使用标准缩放器而不是minMaxScaler)
for n in range(2,5):
for x in range(2,n):
print(n,x)
Run Code Online (Sandbox Code Playgroud)
输出为:
3 2
4 2
4 3
Run Code Online (Sandbox Code Playgroud)
为什么n的值从3开始而不是2?
python ×5
pandas ×2
python-3.x ×2
data-science ×1
dataframe ×1
random ×1
range ×1
replace ×1
scikit-learn ×1
string ×1