pd 相关问题


创建数字范围作为数据框的列

我的数据框是: 将 pandas 导入为 pd df = pd.DataFrame( { 'a': [20, 100], 'b': [2, 3], 'dir': ['长', '短'] } ) 预期输出:创建列...


为什么 LightGBM 中 R2 分数为零?

将 numpy 导入为 np 将 pandas 导入为 pd 导入lightgbm 从 sklearn.metrics 导入 r2_score,mean_squared_error 作为 MSE 数据集 = pd.read_excel("Prali Marble.xlsx") X = dataset.iloc[:,2].va...


Pandas - 使用可变长度滚动窗口聚合值

以下数据框用作输入: 将 pandas 导入为 pd 将 numpy 导入为 np json_string = '{"日期时间":{"0":1528955662000,"1":1528959255000,"2":


pandas 系列替换为回填替代品

pandas.Series.replace 的文档包含一个示例: >> 将 pandas 导入为 pd >> s = pd.Series([1, 2, 3, 4, 5]) >> s.replace([1, 2], method='bfill') 0 3 1 3 2 3 ...


读取和过滤 CSV 文件列

我正在读取数据帧并使用如下条件查找len: 将 pandas 导入为 pd gf = pd.read_csv(raw_github_csv_file_url) print(len(gf[gf["性别"]=="男"])) 我的 CSV...


如何使用BeautifulSoup从网站提取内容?

我必须从该网站文本中提取文章内容 从 bs4 导入 BeautifulSoup 导入请求 将 pandas 导入为 pd url = 'https://economictimes.indiatimes.com/industry/cons-products/food...


两列之和应根据 Pandas 中的结果得出两列之一

我有这个数据集 将 pandas 导入为 pd 数据 = pd.DataFrame({ ‘ID’: [1,2,3,4,5,2,3,1], '借方': [0, 5000, 0, 5000, 3000, 0, 2000, 1000], “信用”:[-100, 0, -700, 0, 0, -8000, ...


查找其中一列发生移动的两列之间的最大值

我的数据框是: 将 pandas 导入为 pd df = pd.DataFrame( { “一”:[20,9,31,40], 'b': [1, 10, 17, 30], } ) 预期输出:创建列 c ABC 0 20 1 20 1 9...


使用 df.apply() 返回多个值

在下面的程序中,我想在调用 df.apply(custom_function) 时将消息作为单独的变量返回。 可以这样做吗 将 pandas 导入为 pd data = {'Column1': [1, 2, 3, 4, 5], '列...


获取每个组值的列表列表,而无需在 pandas 中旋转表格

我有以下数据框: 将 numpy 导入为 np 将 pandas 导入为 pd 数据 = np.random.uniform(0, 1, (4, 5)) df = pd.DataFrame(数据, 列 = [2010,2011,2012,2013,2014]) df = df.stack().reset_ind...


模块“pandas”没有属性“read_csv

将 pandas 导入为 pd df = pd.read_csv('FBI-CRIME11.csv') 打印(df.head()) 运行这个简单的代码会出现错误: 回溯(最近一次调用最后一次): 文件“C:/Users/Dita/Desktop/python/les...


前一天数据填写N/A

我有一个数据框,它只有工作日的数据。以下是示例数据框: 将 pandas 导入为 pd df = pd.DataFrame({'BAS_DT': ['2023-01-02', '2023-01-03', '2023-01-04', '2023-01-05', '2023-01-05 ...


使用 Yfinance 获取市值数据

我试图使用 yfinance 获取股票的市值数据。这是我的代码: 将 yfinance 导入为 yf 将 numpy 导入为 np 从 pandas_datareader 导入数据 将 pandas 导入为 pd 导入 pandas_dataread...


减小表格子图之间的大小

我正在尝试将两个表添加到报告中,但表之间的空间存在问题。通过 MRE: 将 pandas 导入为 pd 将plotly.express导入为px 导入plotly.graph_objects作为go ...


matplotlib 散点图图例不依赖于点的颜色

我想让散点图的图例不依赖于点的颜色。简单的例子如下: 将 matplotlib.pyplot 导入为 plt 将 numpy 导入为 np 将 pandas 导入为 pd 假数据...


我的网络爬虫烧瓶应用程序不断收到内部服务器错误

从flask导入Flask,render_template 从 bs4 导入 BeautifulSoup 导入请求 将 pandas 导入为 pd 应用程序=烧瓶(__名称__) @app.route("/") def job_scraper(): url01 = "htt...


合并索引上的两个数据帧,去掉 key_0

我想通过索引列合并两个数据帧。我的代码是: 将 pandas 导入为 pd 将 numpy 导入为 np df1 = pd.DataFrame({'a': ['红色', '红色', '红色']}) df2 = pd.DataFrame({'b': [1, 2, 2]}) df = ...


Pandas - Lambda 内部应用以返回一行

我原本期望在 Pandas DataFrame 中的 apply 中使用 lambda 函数时获得整行,但看起来我得到了一个“单个元素”。 看那段代码: # 数据样本 评论_2 = pd。


如何在 pandas 中的特定列索引处插入列?

我可以在 pandas 的特定列索引处插入列吗? 将 pandas 导入为 pd df = pd.DataFrame({'l':['a','b','c','d'], 'v':[1,2,1,2]}) df['n'] = 0 这会将第 n 列作为...的最后一列


np.select 将所有真实值连接在一起

我有一个数据框,想检查每一行我的条件是否正确。如果 multiple 为真,我想用 np.select 返回所有这些选择。我怎样才能做到这一点? df = pd。


无法解决 KeyError:“索引 'slice(None, None, None)' 对于索引组件 'MindtPy_utils.objective_value' 无效”

将 pandas 导入为 pd 将随机导入为 r 将 numpy 导入为 np 导入glpk 从 pyomo.environ 导入 * 从amplpy导入AMPL def pyblock(pyp,pytau,pyr,pys): M = 具体模型() MM = ...


如何在pandas中获取常见的时间间隔

我使用的是pandas版本1.0.5 将 pandas 导入为 pd 数据1 = [ ['2023-12-27','2023-12-27 00:00:00','2023-12-27 02:14:00'], ['2023-12-27','2023-12-27 03:16:00','2023-12-27 04:19:00'], ['20...


ValueError:无法将字符串转换为浮点数:'RL'

我正在尝试从 csv 数据绘制热图,但这是我得到的值错误 将 numpy 导入为 np 将 pandas 导入为 pd 将 matplotlib.pyplot 导入为 plt 将seaborn导入为sns 我上传...


如何在绘图中制作包含两个连续条形的直方图?

我有以下代码: 将 pandas 导入为 pd 将 numpy 导入为 np 将 matplotlib.pyplot 导入为 plt # 示例数据(将其替换为您的实际 DataFrame) 数据 = { ‘CU’: [1.5, 2.3, 1.8, 3.2, 2....


使用 Z - Score 方法删除 pandas 数据框中具有异常值的行

我正在使用此代码来删除异常值。 将 pandas 导入为 pd 将 numpy 导入为 np 从 scipy 导入统计数据 df = pd.DataFrame(np.random.randn(100, 3)) df[np.abs(stats.zscore(df[0])) < 1.5] This wo...


为什么当保存为 .svg 而不是 .png 时,图中会出现不需要的线条

导入 matplotlib.pyplot 作为 plt 将 pandas 导入为 pd 将 numpy 导入为 np 导入操作系统 从 matplotlib.ticker 导入 FuncFormatter # 假设数据集已经定义 数据集2 = #redacted # 设置


将时间列从“对象”转换为“日期时间”数据类型后使用 df,我注意到数据发生变化,并且此变化不在位置

将 pandas 导入为 pd order_details_id order_id order_date order_time item_id 0 1 1 1/1/23 11:38:36 上午 109.0 1 2 2 1/1/23 11:5...


© www.soinside.com 2019 - 2024. All rights reserved.