一、TXT文件操作

读取全部内容

  1. import numpy as np
  2. import pandas as pd
  1. txt_filename = './files/python_wiki.txt'
  2. # 打开文件
  3. file_obj = open(txt_filename,'r')
  4. # 读取整个文件内容
  5. all_content = file_obj.read()
  6. # 关闭文件
  7. file_obj.close()
  8. print (all_content)
  1. Python is a widely used high-level, general-purpose, interpreted, dynamic programming language.[24][25] Its design philosophy emphasizes code readability, and its syntax allows programmers to express concepts in fewer lines of code than possible in languages such as C++ or Java.[26][27] The language provides constructs intended to enable writing clear programs on both a small and large scale.[28]
  2. Python supports multiple programming paradigms, including object-oriented, imperative and functional programming or procedural styles. It features a dynamic type system and automatic memory management and has a large and comprehensive standard library.[29]
  3. Python interpreters are available for many operating systems, allowing Python code to run on a wide variety of systems. CPython, the reference implementation of Python, is open source software[30] and has a community-based development model, as do nearly all of its variant implementations. CPython is managed by the non-profit Python Software Foundation.

逐行读取

  1. txt_filename = './files/python_wiki.txt'
  2. # 打开文件
  3. file_obj = open(txt_filename, 'r')
  4. # 逐行读取
  5. line1 = file_obj.readline()
  6. print (line1)
  1. Python is a widely used high-level, general-purpose, interpreted, dynamic programming language.[24][25] Its design philosophy emphasizes code readability, and its syntax allows programmers to express concepts in fewer lines of code than possible in languages such as C++ or Java.[26][27] The language provides constructs intended to enable writing clear programs on both a small and large scale.[28]
  1. # 继续读下一行【不会全部读完】
  2. line2 = file_obj.readline()
  3. print (line2)
  4. # 关闭文件
  5. file_obj.close()
  1. Python supports multiple programming paradigms, including object-oriented, imperative and functional programming or procedural styles. It features a dynamic type system and automatic memory management and has a large and comprehensive standard library.[29]

读取全部内容,返回列表

  1. txt_filename = './files/python_wiki.txt'
  2. # 打开文件
  3. file_obj = open(txt_filename, 'r')
  4. lines = file_obj.readlines()
  5. for i, line in enumerate(lines):
  6. print ('%i: %s' %(i, line))
  7. # 关闭文件
  8. file_obj.close()
  1. 0: Python is a widely used high-level, general-purpose, interpreted, dynamic programming language.[24][25] Its design philosophy emphasizes code readability, and its syntax allows programmers to express concepts in fewer lines of code than possible in languages such as C++ or Java.[26][27] The language provides constructs intended to enable writing clear programs on both a small and large scale.[28]
  2. 1: Python supports multiple programming paradigms, including object-oriented, imperative and functional programming or procedural styles. It features a dynamic type system and automatic memory management and has a large and comprehensive standard library.[29]
  3. 2: Python interpreters are available for many operating systems, allowing Python code to run on a wide variety of systems. CPython, the reference implementation of Python, is open source software[30] and has a community-based development model, as do nearly all of its variant implementations. CPython is managed by the non-profit Python Software Foundation.

写操作

  1. txt_filename = './files/test_write.txt'
  2. # 打开文件
  3. file_obj = open(txt_filename, 'w')
  4. # 写入全部内容
  5. file_obj.write("《Python数据分析》")
  6. file_obj.close()
  1. txt_filename = './files/test_write.txt'
  2. # 打开文件
  3. file_obj = open(txt_filename, 'w')
  4. # 写入字符串列表
  5. lines = ['这是第%i行\n' %n for n in range(10)]
  6. file_obj.writelines(lines)
  7. file_obj.close()

with语句

  1. txt_filename = './files/test_write.txt'
  2. with open(txt_filename, 'r') as f_obj:
  3. print (f_obj.read())
  1. 这是第0
  2. 这是第1
  3. 这是第2
  4. 这是第3
  5. 这是第4
  6. 这是第5
  7. 这是第6
  8. 这是第7
  9. 这是第8
  10. 这是第9

二、CSV文件操作

pandas读csv文件

根据路径导入数据以及指定的列

  1. import pandas as pd
  2. filename = './files/presidential_polls.csv'
  3. df = pd.read_csv(filename, usecols=['cycle', 'type', 'startdate'])#导入指定列
  4. print (type(df))
  5. print (df.head())
  1. <class 'pandas.core.frame.DataFrame'>
  2. cycle type startdate
  3. 0 2016 polls-plus 10/25/2016
  4. 1 2016 polls-plus 10/27/2016
  5. 2 2016 polls-plus 10/27/2016
  6. 3 2016 polls-plus 10/20/2016
  7. 4 2016 polls-plus 10/20/2016

引用指定的列

  1. cycle_se = df['cycle']
  2. print (type(cycle_se))
  3. print (cycle_se.head())
  1. <class 'pandas.core.series.Series'>
  2. 0 2016
  3. 1 2016
  4. 2 2016
  5. 3 2016
  6. 4 2016
  7. Name: cycle, dtype: int64

多层索引成dataframe类型

  1. filename = './files/presidential_polls.csv'
  2. df1 = pd.read_csv(filename,usecols=['cycle', 'type', 'startdate','state','grade'],index_col = ['state','grade'])
  3. print(df1.head())
  1. cycle type startdate
  2. state grade
  3. U.S. B 2016 polls-plus 10/25/2016
  4. A+ 2016 polls-plus 10/27/2016
  5. Virginia A+ 2016 polls-plus 10/27/2016
  6. Florida A 2016 polls-plus 10/20/2016
  7. U.S. B+ 2016 polls-plus 10/20/2016

跳过指定的行

  1. filename = './files/presidential_polls.csv'
  2. df2 = pd.read_csv(filename,usecols=['cycle', 'type', 'startdate','state','grade'],skiprows=[1, 2, 3])
  3. print(df2.head())
  1. cycle type state startdate grade
  2. 0 2016 polls-plus Florida 10/20/2016 A
  3. 1 2016 polls-plus U.S. 10/20/2016 B+
  4. 2 2016 polls-plus U.S. 10/22/2016 A
  5. 3 2016 polls-plus U.S. 10/26/2016 A-
  6. 4 2016 polls-plus Pennsylvania 10/25/2016 B-

pandas写csv文件

·to_csv里面的index参数作用?===可能是不要索引的意思。

  1. filename = './files/pandas_output.csv'
  2. df.to_csv(filename, index=None)

三、JSON文件操作

json读操作

  1. import json
  2. filename = './files/global_temperature.json'
  3. with open(filename, 'r') as f_obj:
  4. json_data = json.load(f_obj)
  5. # 返回值是dict类型
  6. print (type(json_data))
  1. <class 'dict'>
  1. print (json_data.keys())
  1. dict_keys(['description', 'data'])

json转CSV

  1. #print json_data['data'].keys()
  2. print (json_data['data'].values())
  1. dict_values(['-0.1247', '-0.0707', '-0.0710', '-0.1481', '-0.2099', '-0.2220', '-0.2101', '-0.2559', '-0.1541', '-0.1032', '-0.3233', '-0.2552', '-0.3079', '-0.3221', '-0.2828', '-0.2279', '-0.0971', '-0.1232', '-0.2578', '-0.1172', '-0.0704', '-0.1471', '-0.2535', '-0.3442', '-0.4240', '-0.2967', '-0.2208', '-0.3767', '-0.4441', '-0.4332', '-0.3862', '-0.4367', '-0.3318', '-0.3205', '-0.1444', '-0.0747', '-0.2979', '-0.3193', '-0.2118', '-0.2082', '-0.2152', '-0.1517', '-0.2318', '-0.2161', '-0.2510', '-0.1464', '-0.0618', '-0.1506', '-0.1749', '-0.2982', '-0.1016', '-0.0714', '-0.1214', '-0.2481', '-0.1075', '-0.1445', '-0.1173', '-0.0204', '-0.0318', '-0.0157', '0.0927', '0.1974', '0.1549', '0.1598', '0.2948', '0.1754', '-0.0013', '-0.0455', '-0.0471', '-0.0550', '-0.1579', '-0.0095', '0.0288', '0.0997', '-0.1118', '-0.1305', '-0.1945', '0.0538', '0.1145', '0.0640', '0.0252', '0.0818', '0.0924', '0.1100', '-0.1461', '-0.0752', '-0.0204', '-0.0112', '-0.0282', '0.0937', '0.0383', '-0.0775', '0.0280', '0.1654', '-0.0698', '0.0060', '-0.0769', '0.1996', '0.1139', '0.2288', '0.2651', '0.3024', '0.1836', '0.3429', '0.1510', '0.1357', '0.2308', '0.3710', '0.3770', '0.2982', '0.4350', '0.4079', '0.2583', '0.2857', '0.3420', '0.4593', '0.3225', '0.5185', '0.6335', '0.4427', '0.4255', '0.5455', '0.6018', '0.6145', '0.5806', '0.6583', '0.6139', '0.6113', '0.5415', '0.6354', '0.7008', '0.5759', '0.6219', '0.6687', '0.7402', '0.8990'])
  1. # 转换key
  2. year_str_lst = json_data['data'].keys()
  3. year_lst = [int(year_str) for year_str in year_str_lst]
  4. print (year_lst)
  1. [1880, 1881, 1882, 1883, 1884, 1885, 1886, 1887, 1888, 1889, 1890, 1891, 1892, 1893, 1894, 1895, 1896, 1897, 1898, 1899, 1900, 1901, 1902, 1903, 1904, 1905, 1906, 1907, 1908, 1909, 1910, 1911, 1912, 1913, 1914, 1915, 1916, 1917, 1918, 1919, 1920, 1921, 1922, 1923, 1924, 1925, 1926, 1927, 1928, 1929, 1930, 1931, 1932, 1933, 1934, 1935, 1936, 1937, 1938, 1939, 1940, 1941, 1942, 1943, 1944, 1945, 1946, 1947, 1948, 1949, 1950, 1951, 1952, 1953, 1954, 1955, 1956, 1957, 1958, 1959, 1960, 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015]
  1. # 转换value
  2. temp_str_lst = json_data['data'].values()
  3. temp_lst = [float(temp_str) for temp_str in temp_str_lst]
  4. print (temp_lst)
  1. [-0.1247, -0.0707, -0.071, -0.1481, -0.2099, -0.222, -0.2101, -0.2559, -0.1541, -0.1032, -0.3233, -0.2552, -0.3079, -0.3221, -0.2828, -0.2279, -0.0971, -0.1232, -0.2578, -0.1172, -0.0704, -0.1471, -0.2535, -0.3442, -0.424, -0.2967, -0.2208, -0.3767, -0.4441, -0.4332, -0.3862, -0.4367, -0.3318, -0.3205, -0.1444, -0.0747, -0.2979, -0.3193, -0.2118, -0.2082, -0.2152, -0.1517, -0.2318, -0.2161, -0.251, -0.1464, -0.0618, -0.1506, -0.1749, -0.2982, -0.1016, -0.0714, -0.1214, -0.2481, -0.1075, -0.1445, -0.1173, -0.0204, -0.0318, -0.0157, 0.0927, 0.1974, 0.1549, 0.1598, 0.2948, 0.1754, -0.0013, -0.0455, -0.0471, -0.055, -0.1579, -0.0095, 0.0288, 0.0997, -0.1118, -0.1305, -0.1945, 0.0538, 0.1145, 0.064, 0.0252, 0.0818, 0.0924, 0.11, -0.1461, -0.0752, -0.0204, -0.0112, -0.0282, 0.0937, 0.0383, -0.0775, 0.028, 0.1654, -0.0698, 0.006, -0.0769, 0.1996, 0.1139, 0.2288, 0.2651, 0.3024, 0.1836, 0.3429, 0.151, 0.1357, 0.2308, 0.371, 0.377, 0.2982, 0.435, 0.4079, 0.2583, 0.2857, 0.342, 0.4593, 0.3225, 0.5185, 0.6335, 0.4427, 0.4255, 0.5455, 0.6018, 0.6145, 0.5806, 0.6583, 0.6139, 0.6113, 0.5415, 0.6354, 0.7008, 0.5759, 0.6219, 0.6687, 0.7402, 0.899]
  1. import pandas as pd
  2. # 构建 dataframe
  3. year_se = pd.Series(year_lst, name = 'year')
  4. temp_se = pd.Series(temp_lst, name = 'temperature')
  5. result_df = pd.concat([year_se, temp_se], axis = 1)
  6. print (result_df.head())
  7. # 保存csv
  8. result_df.to_csv('./files/json_to_csv.csv', index = None)
  1. year temperature
  2. 0 1880 -0.1247
  3. 1 1881 -0.0707
  4. 2 1882 -0.0710
  5. 3 1883 -0.1481
  6. 4 1884 -0.2099

写json操作

  1. book_dict = [{'书名':'无声告白', '作者':'伍绮诗'}, {'书名':'我不是潘金莲', '作者':'刘震云'}, {'书名':'沉默的大多数 (王小波集)', '作者':'王小波'}]
  2. filename = './files/json_output.json'
  3. with open(filename, 'w') as f_obj:
  4. f_obj.write(json.dumps(book_dict, ensure_ascii=False))
  5. # 不需要加, encoding='utf-8'参数

四、SQLite基本操作

连接数据库

  1. import sqlite3
  2. db_path = './files/test.sqlite'
  3. conn = sqlite3.connect(db_path)
  4. cur = conn.cursor()
  5. conn.text_factory = str # 处理中文

获取基本信息

  1. cur.execute('SELECT SQLITE_VERSION()')
  2. print ('SQLite版本:%s' %str(cur.fetchone()[0]))
  1. SQLite版本:3.30.0

逐条插入数据

  1. cur.execute("DROP TABLE IF EXISTS book")
  2. cur.execute("CREATE TABLE book(id INT, name TEXT, price DOUBLE)")
  3. cur.execute("INSERT INTO book VALUES(1,'肖秀荣考研书系列:肖秀荣(2017)考研政治命题人终极预测4套卷',14.40)")
  4. cur.execute("INSERT INTO book VALUES(2,'法医秦明作品集:幸存者+清道夫+尸语者+无声的证词+第十一根手指(套装共5册) (两种封面随机发货)',100.00)")
  5. cur.execute("INSERT INTO book VALUES(3,'活着本来单纯:丰子恺散文漫画精品集(收藏本)',30.90)")
  6. cur.execute("INSERT INTO book VALUES(4,'自在独行:贾平凹的独行世界',26.80)")
  7. cur.execute("INSERT INTO book VALUES(5,'当你的才华还撑不起你的梦想时',23.00)")
  8. cur.execute("INSERT INTO book VALUES(6,'巨人的陨落(套装共3册)',84.90)")
  9. cur.execute("INSERT INTO book VALUES(7,'孤独深处(收录雨果奖获奖作品《北京折叠》)',21.90)")
  10. cur.execute("INSERT INTO book VALUES(8,'世界知名企业员工指定培训教材:所谓情商高,就是会说话',22.00)")
  1. <sqlite3.Cursor at 0x2d2d64e7c00>

批量插入数据

  1. books = (
  2. (9, '人间草木', 30.00),
  3. (10,'你的善良必须有点锋芒', 20.50),
  4. (11, '这么慢,那么美', 24.80),
  5. (12, '考拉小巫的英语学习日记:写给为梦想而奋斗的人(全新修订版)', 23.90)
  6. )
  7. cur.executemany("INSERT INTO book VALUES(?, ?, ?)", books)
  1. <sqlite3.Cursor at 0x2d2d64e7c00>
  1. conn.commit()

查找数据

  1. cur.execute('SELECT * FROM book')
  2. rows = cur.fetchall()
  3. # 通过索引号访问
  4. for row in rows:
  5. print ('序号: %i, 书名: %s, 价格: %.2f' %(row[0], row[1], row[2]))
  1. 序号: 1, 书名: 肖秀荣考研书系列:肖秀荣(2017)考研政治命题人终极预测4套卷, 价格: 14.40
  2. 序号: 2, 书名: 法医秦明作品集:幸存者+清道夫+尸语者+无声的证词+第十一根手指(套装共5册) (两种封面随机发货), 价格: 100.00
  3. 序号: 3, 书名: 活着本来单纯:丰子恺散文漫画精品集(收藏本), 价格: 30.90
  4. 序号: 4, 书名: 自在独行:贾平凹的独行世界, 价格: 26.80
  5. 序号: 5, 书名: 当你的才华还撑不起你的梦想时, 价格: 23.00
  6. 序号: 6, 书名: 巨人的陨落(套装共3册), 价格: 84.90
  7. 序号: 7, 书名: 孤独深处(收录雨果奖获奖作品《北京折叠》), 价格: 21.90
  8. 序号: 8, 书名: 世界知名企业员工指定培训教材:所谓情商高,就是会说话, 价格: 22.00
  9. 序号: 9, 书名: 人间草木, 价格: 30.00
  10. 序号: 10, 书名: 你的善良必须有点锋芒, 价格: 20.50
  11. 序号: 11, 书名: 这么慢,那么美, 价格: 24.80
  12. 序号: 12, 书名: 考拉小巫的英语学习日记:写给为梦想而奋斗的人(全新修订版), 价格: 23.90
  1. conn.row_factory = sqlite3.Row
  2. cur = conn.cursor()
  3. cur.execute('SELECT * FROM book')
  4. rows = cur.fetchall()
  5. # 通过列名访问
  6. for row in rows:
  7. print ('序号: %i, 书名: %s, 价格: %.2f' %(row['id'], row['name'], row['price']))
  1. 序号: 1, 书名: 肖秀荣考研书系列:肖秀荣(2017)考研政治命题人终极预测4套卷, 价格: 14.40
  2. 序号: 2, 书名: 法医秦明作品集:幸存者+清道夫+尸语者+无声的证词+第十一根手指(套装共5册) (两种封面随机发货), 价格: 100.00
  3. 序号: 3, 书名: 活着本来单纯:丰子恺散文漫画精品集(收藏本), 价格: 30.90
  4. 序号: 4, 书名: 自在独行:贾平凹的独行世界, 价格: 26.80
  5. 序号: 5, 书名: 当你的才华还撑不起你的梦想时, 价格: 23.00
  6. 序号: 6, 书名: 巨人的陨落(套装共3册), 价格: 84.90
  7. 序号: 7, 书名: 孤独深处(收录雨果奖获奖作品《北京折叠》), 价格: 21.90
  8. 序号: 8, 书名: 世界知名企业员工指定培训教材:所谓情商高,就是会说话, 价格: 22.00
  9. 序号: 9, 书名: 人间草木, 价格: 30.00
  10. 序号: 10, 书名: 你的善良必须有点锋芒, 价格: 20.50
  11. 序号: 11, 书名: 这么慢,那么美, 价格: 24.80
  12. 序号: 12, 书名: 考拉小巫的英语学习日记:写给为梦想而奋斗的人(全新修订版), 价格: 23.90
  1. conn.close()

五、SQLite_json操作

  1. import sqlite3
  2. db_path = './files/test_join.sqlite'
  3. conn = sqlite3.connect(db_path)
  4. cur = conn.cursor()
  1. # 建 depaetment 表,并插入数据
  2. cur.execute("DROP TABLE IF EXISTS department")
  3. cur.execute("CREATE TABLE department(\
  4. id INT PRIMARY KEY NOT NULL, \
  5. dept CHAR(50) NOT NULL, \
  6. emp_id INT NOT NULL)")
  7. depts = (
  8. (1, 'IT Builing', 1),
  9. (2, 'Engineerin', 2),
  10. (3, 'Finance', 7)
  11. )
  12. cur.executemany("INSERT INTO department VALUES(?, ?, ?)", depts)
  1. <sqlite3.Cursor at 0x2d2d64f70a0>
  1. conn.commit()

CROSS JOIN 交叉连接

  1. cur.execute("SELECT emp_id, name, dept FROM company CROSS JOIN department;")
  2. rows = cur.fetchall()
  3. for row in rows:
  4. print (row)
  1. # 建 company 表,并插入数据
  2. cur.execute("DROP TABLE IF EXISTS company")
  3. cur.execute("CREATE TABLE company(\
  4. id INT PRIMARY KEY NOT NULL, \
  5. name CHAR(50) NOT NULL, \
  6. age INT NOT NULL, \
  7. address CHAR(50) NOT NULL,\
  8. salary DOUBLE NOT NULL)")
  9. companies = (
  10. (1, 'Paul', 32, 'California', 20000.0),
  11. (2, 'Allen', 25, 'Texas', 15000.0),
  12. (3, 'Teddy', 23, 'Norway', 20000.0),
  13. (4, 'Mark', 25, 'Rich-Mond', 65000.0),
  14. (5, 'David', 27, 'Texas', 85000.0),
  15. (6, 'Kim', 22, 'South-Hall', 45000.0),
  16. (7, 'James', 24, 'Houston', 10000.0)
  17. )
  18. cur.executemany("INSERT INTO company VALUES (?, ?, ?, ?, ?)", companies)
  1. <sqlite3.Cursor at 0x2d2d64f70a0>

INNER JOIN 内连接

  1. cur.execute("SELECT emp_id, name, dept FROM company INNER JOIN department \
  2. ON company.id = department.emp_id;")
  3. rows = cur.fetchall()
  4. for row in rows:
  5. print (row)
  1. (1, 'Paul', 'IT Builing')
  2. (2, 'Allen', 'Engineerin')
  3. (7, 'James', 'Finance')

OUTER JOIN 外连接

  1. # 左连接
  2. cur.execute("SELECT emp_id, name, dept FROM company LEFT OUTER JOIN department \
  3. ON company.id = department.emp_id;")
  4. rows = cur.fetchall()
  5. for row in rows:
  6. print (row)
  1. (1, 'Paul', 'IT Builing')
  2. (2, 'Allen', 'Engineerin')
  3. (None, 'Teddy', None)
  4. (None, 'Mark', None)
  5. (None, 'David', None)
  6. (None, 'Kim', None)
  7. (7, 'James', 'Finance')
  1. # 右连接 (目前不支持)
  2. cur.execute("SELECT emp_id, name, dept FROM company RIGHT OUTER JOIN department \
  3. ON company.id = department.emp_id;")
  4. rows = cur.fetchall()
  5. for row in rows:
  6. print (row)
  1. ---------------------------------------------------------------------------
  2. OperationalError Traceback (most recent call last)
  3. <ipython-input-41-ce0fc573748b> in <module>
  4. 1 # 右连接 (目前不支持)
  5. 2 cur.execute("SELECT emp_id, name, dept FROM company RIGHT OUTER JOIN department \
  6. ----> 3 ON company.id = department.emp_id;")
  7. 4 rows = cur.fetchall()
  8. 5 for row in rows:
  9. OperationalError: RIGHT and FULL OUTER JOINs are not currently supported
  1. # 右连接,交换两张表
  2. cur.execute("SELECT emp_id, name, dept FROM department LEFT OUTER JOIN company \
  3. ON company.id = department.emp_id;")
  4. rows = cur.fetchall()
  5. for row in rows:
  6. print (row)
  1. (1, 'Paul', 'IT Builing')
  2. (2, 'Allen', 'Engineerin')
  3. (7, 'James', 'Finance')
  1. sqlite> SELECT EMP_ID, NAME, DEPT FROM COMPANY LEFT OUTER JOIN DEPARTMENT
  2. ON COMPANY.ID = DEPARTMENT.EMP_ID;
  1. File "<ipython-input-43-a0833b733075>", line 1
  2. sqlite> SELECT EMP_ID, NAME, DEPT FROM COMPANY LEFT OUTER JOIN DEPARTMENT
  3. ^
  4. SyntaxError: invalid syntax

六、Excel文件操作

pandas.read_excel(io, sheet_name=0, header=0, names=None, index_col=None, usecols=None, squeeze=False, dtype=None, engine=None, converters=None, true_values=None, false_values=None, skiprows=None, nrows=None, na_values=None, keep_default_na=True, verbose=False, parse_dates=False, date_parser=None, thousands=None, comment=None, skipfooter=0, convert_float=True, mangle_dupe_cols=True, **kwds)

df_fujian = pd.read_excel(“./datafiles/fujian.xlsx”,sheet_name=’日数据’)

Jupyter Notebook的安装

一般有两种方法,第一种是下载Anaconda,自带python环境以及Jupyter Notebook环境,但这一般都是刚学机器学习那会的集成安装方式,最主要的劝退原因是所占体积较大,所以这里介绍原生的安装方式,在纯Python环境下,使用自带的pip包管理工具下载,类似地像Pandas、Numpy等包也可以以此种方式安装

打脸YYDS,收回上面画斜线的文字,因为自己以前的笔记里面,有许多其他库,一个一个安装太繁杂了,所以还是下载Anaconda集成环境吧。
Python的本地各类数据读取 - 图1
具体下载配置参考之前的文章:Pycharm,Anaconda,JetBrains系列app相关总结 | 尼采般地抒情

安装python

地址:https://www.python.org/downloads/windows/
image.png
image.png
image.png
安装完之后进入cmd查看
image.png

安装jupyter

  1. pip install jupyter

安装成功之后,在项目文件夹下,打开powershell终端输入:jupyter notebook
image.png

报错

ValueError: check_hostname requires server_hostname

image.png
关掉tizi

ReadTimeoutError: HTTPSConnectionPool(host=’files.pythonhosted.org’, port=443): Read timed out.

image.png
按照报错信息,更新pip

数据分析

本地数据的读取