我尝试将列从数据类型转换float64为int64使用:
df['column name'].astype(int64)
Run Code Online (Sandbox Code Playgroud)
但得到一个错误:
NameError:未定义名称"int64"
该列有多少人,但格式化为7500000.0,任何想法我怎么可以简单地将其更改float64为int64?
我有 3 个文件表示相同的数据集分成 3 个,我需要连接:
import pandas
df1 = pandas.read_csv('path1')
df2 = pandas.read_csv('path2')
df3 = pandas.read_csv('path3')
df = pandas.concat([df1,df2,df3])
Run Code Online (Sandbox Code Playgroud)
但这会将标题保留在数据集的中间,我需要从第二个和第三个文件中删除标题(列名)。我怎么做?
我运行 df.dtypes 并获取某些列的类型“object”。这是否意味着 Pandas 无法判断列类型是什么?或者可以在将这种类型保留在数据框中的同时继续进行分析吗?它是清理数据的一部分,以确保数据框中没有留下类型“对象”吗?
我需要更改内核以将其指向 Python 的 miniconda 版本,但 Jupyter Notebook 在 Kernel-> Change Kernel 下仅显示一个“Python 3”。
知道如何让 Jupyter 笔记本显示已安装的附加笔记本吗?
我在 SharePoint 网站的文档部分有一个 csv。我想在 Pandas 中导入它。当然是我只使用下面的普通代码我得到 HTTP 错误 403 Forbidden。
import pandas
df = pandas.read_csv('link from sharepoint')
Run Code Online (Sandbox Code Playgroud)
如何使用 Python 使 SharePoint 身份验证正常工作,以便 Pandas 可以读取 csv 文件。
我已经在几个互联网帖子中搜索并尝试了代码,但是代码太通用了,我不知道它是什么意思,例如
username = 'YourDomain\\account'
Run Code Online (Sandbox Code Playgroud)
或者
user = r'SERVER\user'
Run Code Online (Sandbox Code Playgroud)
或者它只是没有。
有没有一种简单的方法可以让身份验证工作并在 Pandas 中导入文件?
如何找出 Pandas DataFrame 中缺少数据的总行数?我试过这个:
df.isnull().sum().sum()
Run Code Online (Sandbox Code Playgroud)
但这是针对总缺失字段。我需要知道有多少行受到影响。
我正在尝试从 MS SQL Server 2016 中的表创建 DataFrame,我使用了示例数据库 AdventureWorks2012,代码如下:
import pyodbc
cnxn = pyodbc.connect("Driver={ODBC Driver 13 for SQL Server};"
"Server=localhost;"
"Database=AdventureWorks2012;"
"Trusted_Connection=yes;")
cursor = cnxn.cursor()
cursor.execute('SELECT * FROM HumanResources.Employee')
df = pandas.read_sql(sql, cnxn)
cursor.close()
cnxn.close()
Run Code Online (Sandbox Code Playgroud)
但我收到一个错误:
----> 1 df = pandas.read_sql(sql, cnxn)
ProgrammingError: ('ODBC SQL type -151 is not not supported. column-index=3 type=-151', 'HY106')