[英]What is a pandas.core.Frame.DataFrame, and how to convert it to pd.DataFrame?
Currently I was trying to do a machine learning classification of 6 time series datasets (in.csv format) using MiniRocket, an sktime machine learning package. However, when I imported the.csv files using pd.read_csv and run them through MiniRocket, the error "TypeError: X must be in an sktime compatible format" pops up, and it says that the following data types are sktime compatible: ['pd.Series', 'pd.DataFrame', 'np.ndarray', 'nested_univ', 'numpy3D', 'pd-multiindex', 'df-list', 'pd_multiindex_hier'] Then I checked the data type of my imported.csv files and got "pandas.core.Frame.DataFrame", which is a data type that I never saw before and is obviously different from the sktime compatible pd.DataFrame.目前我正在尝试使用 MiniRocket 对 6 个时间序列数据集(in.csv 格式)进行机器学习分类,这是一个 sktime 机器学习 package。但是,当我使用 pd.read_csv 导入 .csv 文件并通过 MiniRocket 运行它们时,弹出错误“TypeError: X must be in an sktime compatible format”,它表示以下数据类型与 sktime 兼容:['pd.Series', 'pd.DataFrame', 'np.ndarray', 'nested_univ' , 'numpy3D', 'pd-multiindex', 'df-list', 'pd_multiindex_hier'] 然后我检查了我imported.csv文件的数据类型,得到了“pandas.core.Frame.DataFrame”,这是一个数据类型我以前从未见过,并且与 sktime 兼容的 pd.DataFrame 明显不同。 What is the difference between pandas.core.Frame.DataFrame and pd.DataFrame, and how to convert pandas.core.Frame.DataFrame to the sktime compatible pd.DataFrame?
pandas.core.Frame.DataFrame 和 pd.DataFrame 有什么区别,如何将 pandas.core.Frame.DataFrame 转换为 sktime 兼容的 pd.DataFrame?
I tried to convert pandas.core.Frame.DataFrame to pd.DataFrame using df.join and df.pop functions, but neither of them was able to convert my data from pandas.core.Frame.DataFrame to pd.DataFrame (after conversion I checked the type again and it is still the same).我尝试使用 df.join 和 df.pop 函数将 pandas.core.Frame.DataFrame 转换为 pd.DataFrame,但它们都无法将我的数据从 pandas.core.Frame.DataFrame 转换为 pd.DataFrame(转换后我再次检查了类型,它仍然是相同的)。
If you just take the values from your old DataFrame with .values
, you can create a new DataFrame the standard way.如果您只是使用 .values 从旧的
.values
中获取值,则可以以标准方式创建一个新的 DataFrame。 If you want to keep the same columns and index values, just set those when you declare your new DataFrame.如果您想保留相同的列和索引值,只需在声明新的 DataFrame 时设置它们。
df_new = pd.DataFrame(df_old.values, columns=df_old.columns, index=df_old.index)
Most of the pandas classes are defined under pandas.core
folder: https://github.com/pandas-dev/pandas/tree/main/pandas/core .大多数 pandas 类都在
pandas.core
文件夹下定义: https://github.com/pandas-dev/pandas/tree/main/pandas/core 。
For example, class DataFrame
is defined in pandas.core.frame.py
:例如 class
DataFrame
在pandas.core.frame.py
中定义:
class DataFrame(NDFrame, OpsMixin):
...
def __init__(...)
...
Pandas is not yet a py.typed library PEP 561 , hence the public API documentation uses pandas.DataFrame
but internally all error messages still refer to the source file structure such as pandas.core.frame.DataFrame
. Pandas 还不是 py.typed 库PEP 561 ,因此公共 API 文档使用
pandas.DataFrame
但内部所有错误消息仍然引用源文件结构,例如pandas.core.frame.DataFrame
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.