File size: 2,752 Bytes
25e92b9
 
 
 
3de6db3
25e92b9
 
 
3de6db3
25e92b9
 
 
 
3de6db3
25e92b9
 
 
3de6db3
 
 
 
 
 
 
25e92b9
3de6db3
 
25e92b9
 
 
 
 
 
3de6db3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25e92b9
 
3de6db3
 
 
 
 
 
 
 
25e92b9
 
 
 
3de6db3
 
 
 
 
 
 
 
 
25e92b9
 
 
 
3de6db3
25e92b9
3de6db3
 
 
 
 
 
 
 
 
 
 
 
25e92b9
3de6db3
 
25e92b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 定义要写入的数据\n",
    "data = [\n",
    "    ['王五', '19', '河北', 'kk']\n",
    "]\n",
    "\n",
    "# 创建DataFrame对象\n",
    "df = pd.DataFrame(data, columns=['name', 'age', 'city', 'mark'])\n",
    "\n",
    "# 将DataFrame写入CSV文件\n",
    "df.to_csv('../data/llm_test.csv', index=False, mode='a', header=False)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 读取CSV文件到DataFrame\n",
    "df = pd.read_csv('../data/llm_test.csv')\n",
    "# 修改特定行列的数据\n",
    "row_index = 0  # 要修改的行索引,除去表头,从0开始\n",
    "column_name = 'age'  # 要修改的列名\n",
    "new_value = '2345'  # 修改后的值\n",
    "\n",
    "df.loc[row_index, column_name] = new_value\n",
    "# 将修改后的DataFrame写回到CSV文件\n",
    "df.to_csv('../data/llm_test.csv', index=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "name    2\n",
      "age     2\n",
      "city    2\n",
      "mark    2\n",
      "dtype: int64\n"
     ]
    }
   ],
   "source": [
    "# 读取CSV文件到DataFrame\n",
    "df = pd.read_csv('../data/llm_test.csv')\n",
    "\n",
    "# 查找满足特定条件的行数据\n",
    "condition = df['age'] == 100  # 以Column1列为例,查找值为'Value1'的行\n",
    "filtered_data = df[condition]\n",
    "\n",
    "# 打印查找结果\n",
    "print(filtered_data)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  name  age city mark\n",
      "0   张三  100   河北   kk\n",
      "1   赵四   19   河北   kk\n",
      "2   赵五  100   河北   kk\n"
     ]
    }
   ],
   "source": [
    "df = pd.read_csv('../data/llm_test.csv').head(3)\n",
    "print(df)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.10"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}