pycharm读取数据出现的错误

img

pycharm读取产生以下错误
C:\Users\18368\Desktop\code\class3(1).py:11: FutureWarning: The error_bad_lines argument has been deprecated and will be removed in a future version. Use on_bad_lines in the future.

df = pd.read_csv(
C:\Users\18368\Desktop\code\class3(1).py:11: UserWarning: Parsing dates in DD/MM/YYYY format when dayfirst=False (the default) was specified. This may lead to inconsistently parsed dates! Specify a format to ensure consistent parsing.
df = pd.read_csv(

该回答引用GPTᴼᴾᴱᴺᴬᴵ
这个错误的原因是由于使用了已经被废弃的参数“error_bad_lines”,因此出现了FutureWarning的警告。可以使用新的参数“on_bad_lines”代替它。同时还有一个UserWarning,提示解析日期格式时可能会出现错误,建议使用格式来保证解析的一致性。

下面是修改后的代码示例:

import pandas as pd 

# 导入数据
df = pd.read_csv(
    # 该参数为数据在电脑中的路径,可以不填写
    filepath_or_buffer='C:/Users/18368/Desktop/新建文件夹 (2)/demo/$zeeeee2.csv',
    # 该参数代表数据的分隔符,CSV文件默认是逗号。其他常见的是“\t”
    sep=',',
    # 该参数代表跳过数据文件的的第1行不读入
    skiprows=1,
    # nrows,只读取前n行数据,若不指定,读入全部的数据
    nrows=15,
    # 指定列的数据识别为日期格式。若不指定,数据将会以字符形式读入。
    # 一开始先不用。
    parse_dates=['交易日期'],
    # 指定列设置为index。若不指定,index默认为0,1,2,3,4...
    index_col=['交易日期'],
    # 读取指定的这几列数据,其他数据不读取。若不指定,读入全部列
    usecols=['交易日期', '股票代码', '股票名称', '收盐价', '濕跌幅', '威交量', '新浪研念', 'MACD_金叉死叉了'],
    # 当行数据有问题时,是否报错。设定为False时即不报错,直接跳过该行。
    error_bad_lines=False,
    # 数据中的null识别为空值
    na_values='NULL',
    # 解析日期格式为日月年的形式
    dayfirst=True
)


不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^

日期格式错误,你把格式转换一下就好了