赛博禅心 01月10日
用 AI 对 Excel 数据分析:数据再多也不愁
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

文章探讨了如何利用AI更有效地分析结构化数据,如Excel和CSV文件。由于大语言模型处理长文本和数学运算的限制,文章建议结合代码使用。核心方法是提供数据结构而非完整数据,明确分析需求,并让AI生成代码。文章通过示例展示了ChatGPT和Claude如何分析X平台导出的访问数据,揭示了访问量最高的时间维度,并提供了代码实现和分析结果。这种方法既解决了上下文窗口的限制,又利用了AI的代码生成能力,提高了数据分析的效率和准确性。

💡AI分析结构化数据时,应避免直接粘贴完整数据,而是提供数据结构描述或示例,以防信息丢失。

💻 结合代码使用是关键。AI可生成代码来读取和分析数据,弥补大语言模型在数学运算上的不足。

📅 通过让AI分析示例数据,可以实现按月、周、日等时间维度统计数据,从而找出峰值。

🤖 ChatGPT和Claude等工具都能根据用户需求生成代码,前者使用Python,后者使用JavaScript。

原创 宝玉xp 2025-01-08 18:16 广东

开发新范式:从串行链条,到分流开放

问:

怎么能让 AI 更好地分析我的结构化数据(Excel/CSV)?内容很长感觉就被丢了一些


答:

由于上下文窗口的限制,AI 无法一次性处理很长的内容。此外,大语言模型本身并不擅长数学运算,所以它也无法直接基于你提供的结构化数据去做计算。这时候最好的方法是结合代码使用。

比如,像 ChatGPT、Claude 这样的工具可以自动帮你生成代码来分析数据,甚至可以帮你分批处理数据。如果愿意,你也可以自己写代码实现分析。

 


 

基本原理


    提供数据结构,不要给完整数据:在给 AI 的 prompt 中,只需要描述你数据的结构(比如列名和数据类型),或者给一个小的示例数据。不需要直接粘贴完整的数据,这样可以避免输入内容太长导致部分信息被丢失。

    明确你的需求:清楚地告诉 AI 你想对数据进行什么操作或分析,比如生成统计表、绘图,或者计算某些指标。

    让 AI 生成代码:基于你的需求,让 AI 写出代码来读取和分析数据。这样,代码可以处理你的完整数据并生成准确的结果,而不用担心上下文窗口限制。






示例


比如说,我把我 X 上的访问数据导出成 csv/excel 文件,包含每一天的访问量,然后我把这个数据提交给 ChatGPT(Claude 也可以),让它帮我:“分析我这一年的推文数据中,是哪个月访问量最大?哪一周访问量最大?哪一天访问两最大?” 



ChatGPT 首先会对我的数据进行抽样,了解我的数据结构是什么样的。 

 

然后根据需求去生成代码,最后运行代码获得结果。 


Claude 也是类似,唯一的差别是 ChatGPT 用 Python,而 Claude 使用 JavaScript。 


 

Claude 返回结果: 

我来帮您分析这些数据。我会使用分析工具来处理CSV文件,查看不同时间维度的访问量(Profile visits)数据。
// 读取并解析CSV文件
const fileContent = await window.fs.readFile('account_overview_analytics 2.csv', { encoding: 'utf8' });
import Papa from 'papaparse';
const parsedData = Papa.parse(fileContent, {
  header: true,
  dynamicTyping: true,
  skipEmptyLines: true
});
const data = parsedData.data;
// 按月份分组
const monthlyVisits = {};
data.forEach(row => {
  const date = new Date(row.Date);
  const monthKey = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}`;
  if (!monthlyVisits[monthKey]) {
    monthlyVisits[monthKey] = 0;
  }
  monthlyVisits[monthKey] += row['Profile visits'] || 0;
});
// 找出访问量最大的月份
const maxMonthVisits = Object.entries(monthlyVisits)
  .sort((a, b) => b[1] - a[1])[0];
console.log('月度访问量最高:', maxMonthVisits);
// 按周分组
const weeklyVisits = {};
data.forEach(row => {
  const date = new Date(row.Date);
  const weekNumber = getWeekNumber(date);
  const weekKey = `${date.getFullYear()}-W${String(weekNumber).padStart(2, '0')}`;
  if (!weeklyVisits[weekKey]) {
    weeklyVisits[weekKey] = 0;
  }
  weeklyVisits[weekKey] += row['Profile visits'] || 0;
});
// 找出访问量最大的周
const maxWeekVisits = Object.entries(weeklyVisits)
  .sort((a, b) => b[1] - a[1])[0];
console.log('周访问量最高:', maxWeekVisits);
// 找出访问量最大的天
const dailyVisits = data.map(row => ({
  date: row.Date,
  visits: row['Profile visits'] || 0
}));
const maxDayVisits = dailyVisits.sort((a, b) => b.visits - a.visits)[0];
console.log('日访问量最高:', maxDayVisits);
// 辅助函数:获取日期所在的周数
function getWeekNumber(date) {
  const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
  const dayNum = d.getUTCDay() || 7;
  d.setUTCDate(d.getUTCDate() + 4 - dayNum);
  const yearStart = new Date(Date.UTC(d.getUTCFullYear(),0,1));
  return Math.ceil((((d - yearStart) / 86400000) + 1)/7);
}
根据分析结果:
1. 访问量最高的月份是 2024年2月,总访问量达到了 25,317 次
2. 访问量最高的周是 2024年第7周(2月中旬),访问量为 9,537 次
3. 访问量最高的单日是 2024年2月16日(星期五),当天访问量达到了 4,203 次
看起来2月份是您账号表现最好的时期,特别是2月中旬的那一周。您是否记得在2月16日发布了什么特别的内容,导致访问量激增?这可能对您未来的内容策略有所启发。
如果您想了解更多细节,比如具体的内容类型分析或者其他指标(如互动率、关注率等),我也可以为您进一步分析。


ChatGPT: 

import pandas as pd
# Load the CSV file to analyze the data
file_path = '/mnt/data/account_overview_analytics (2).csv'
data = pd.read_
csv(file_path)
# Display the first few rows to understand the structure of the data
data.head()
Result:
Result
                Date  Impressions  Likes  Engagements  Bookmarks  Shares  \
0  Fri, Dec 27, 2024        17955     65          405         29       1   
1  Thu, Dec 26, 2024      1126219   2870        21818       1386      65   
2  Wed, Dec 25, 2024      1657311   4312        19589       1544      78   
3  Tue, Dec 24, 2024       401326   1424        12266        749      41   
4  Mon, Dec 23, 2024       467837   1528        16703        782      43   
   New follows  Unfollows  Replies  Reposts  Profile visits  Create Post  \
0            4          0       10       10              35            0   
1          206         39      198      427            1099            1   
2          361         23      179      667            1700            3   
3          141         15      153      272             517            5   
4           96         27      217      260             559            2   
   Video views  Media views  
0          242          346  
1        22707        88041  
2        12096        23161  
3        17368        42005  
4        34821        77995  
The dataset includes columns such as Date, Impressions, Likes, and others. To answer your questions regarding:
1. Month with the maximum impressions: I'll group the data by month and calculate total impressions.
2. Week with the maximum impressions: I'll group the data by week and calculate total impressions.
3. Day with the maximum impressions: I'll find the single date with the highest impressions.
Let me proceed with the calculations.
# Convert the 'Date' column to a datetime format for easier grouping
data['Date'] = pd.to_
datetime(data['Date'], format='%a, %b %d, %Y')
# Add helper columns for month and week
data['Month'] = data['Date'].dt.to_period('M')
data['Week'] = data['Date'].dt.isocalendar().week
# Group by month and sum the impressions
monthly_
impressions = data.groupby('Month')['Impressions'].sum()
# Group by week and sum the impressions
weekly_impressions = data.groupby('Week')['Impressions'].sum()
# Find the day with the maximum impressions
max_
day = data.loc[data['Impressions'].idxmax()]
# Extract the results
max_month = monthly_impressions.idxmax()
max_month_value = monthly_impressions.max()
max_
week = weekly_impressions.idxmax()
max_
week_value = weekly_impressions.max()
max_day_date = max_day['Date']
max_
day_value = max_day['Impressions']
(max_month, max_month_value, max_week, max_week_value, max_day_date, max_day_value)
Result
(Period('2024-02', 'M'),
 22484999,
 7,
 7480737,
 Timestamp('2024-02-16 00:00:00'),
 2753640)
Here is the analysis of your tweet impressions:
1. Month with the maximum impressions: February 2024, with a total of 22,484,999 impressions.
2. Week with the maximum impressions: Week 7 (mid-February 2024), with a total of 7,480,737 impressions.
3. Day with the maximum impressions: February 16, 2024, with 2,753,640 impressions.
Let me know if you'd like a more detailed visualization or further breakdown!



阅读原文

跳转微信打开

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

AI数据分析 结构化数据 代码生成 ChatGPT Claude
相关文章