在python中上传CSV文件的问题
我在 python 中上传 excel 数据时遇到一些问题。
Excel:
用于上传的代码:
import pandas as pd
from google.colab import files
#uploaded = files.upload()
import io
df2 = pd.read_csv(io.BytesIO(uploaded['nodes.csv']),index_col=0)
print (df2)
结果:
你能帮我吗?
I have some problem with uploding excel data in python.
Excel:
Code used to upload:
import pandas as pd
from google.colab import files
#uploaded = files.upload()
import io
df2 = pd.read_csv(io.BytesIO(uploaded['nodes.csv']),index_col=0)
print (df2)
Result:
Can you kindly help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您说要将导入的数据转换为numpy阵列,可以通过使用以下方式而无需使用pandas:
检查文档: https://numpy.org/doc/stable/reference/generated/generated/numpy.genfromtxt.htxt.html
You said you wanted to convert the imported data to a numpy array, you could do so by doing the following without using pandas:
Check the documentation: https://numpy.org/doc/stable/reference/generated/numpy.genfromtxt.html
如果您有一个CSV-File
file.csv
,则
确实会产生
为什么:第一行中有两个
0
s,而PANDAS则是 mange dupes /em>因为该行用于标签。0.1
不是数字,它是字符串(print(df.columns)
将显示index(['0.1'],dtype ='对象' )
)。如果您的文件看起来像是输出将
这样,那将不会发生,如果您的目标是Numpy数组,则
导致
If you have a csv-file
file.csv
then
does produce
Why is that: There are two
0
s in the first row and Pandas is mangling the dupes because the row is used for labels. The0.1
isn't a number, it's a string (print(df.columns)
will showIndex(['0.1'], dtype='object')
). If your file would look likethen this wouldn't happen, the output would look like
If your goal is NumPy array, then
leads to