我正在尝试这个熊猫编码问题,但不知道怎么做。下面的代码是我能做的,但它显示了错误。有人能帮我解释一下怎么做吗?谢谢。
Cars数据集有三列,分别给出了18辆汽车的质量、加工角度和加工速度。
编写执行下列任务的程序:
cars_df.
Cars.csv加载到名为的数据框架中。userNum行子集为一个新的数据帧.Ex: If the input is:
5
the output is:
Quality 5
Speed 4
Angle 3
dtype: int64我的代码:
import pandas as pd
cars_df = pd.DataFrame("Cars.csv")# Import the CSV file Cars.csv
userNum = int(input())
# Subset the first userNum rows of the data frame
userNum = pd.iloc[:0,:]
userNum.max()
print(userNum)Traceback (most recent call last):
File "main.py", line 4, in <module>
cars_df = pd.DataFrame("Cars.csv")# Import the CSV file Cars.csv
File "/usr/local/lib/python3.8/dist-packages/pandas/core/frame.py", line 730, in __init__
raise ValueError("DataFrame constructor not properly called!")
ValueError: DataFrame constructor not properly called!我是python的初学者,大多数时候我对编码一无所知。我不知道怎么做这段代码。您的帮助和对此编码的解释将不胜感激。
发布于 2021-12-04 18:32:16
我想这就是你想要的
cars_df = pd.DataFrame("Cars.csv") # Import the CSV file Cars.csv
user_num = int(input())
subset = cars_df.head(user_num)
print(subset.max())而不是最后一行,您可以调用
print(subset.describe())这会给你比.max()更多的数据
https://stackoverflow.com/questions/70220860
复制相似问题