简体   繁体   English

Python中的Panda跳过第一行的计算

[英]Panda in Python skips computation on first line

I have a file with its content as 我有一个文件,其内容为

0.08300343840033242
0.5721455830484666
0.46518116038504165

I ran following script on it: 我在上面运行了以下脚本:

import pandas as pd
import csv
df = pd.read_csv('circle1.csv')
df1 = df**2
print df1

Problem in the output is pandas skips the computation on first line but squares the rest of numbers: 输出中的问题是熊猫在第一行跳过了计算,但对其余数字求平方:

C:\Python27\python.exe C:/Users/Deepak/PycharmProjects/Submission/balnk.py
   0.08300343840033242
0             0.327351
1             0.216394

What is causing this trouble and what can be done to resolve it. 是什么导致了此问题,以及可以解决该问题的方法。

You're not loading your data properly, it appears your CSV has no headers. 您的数据加载不正确,看来CSV没有标题。 In which case, specify header=None . 在这种情况下,请指定header=None

df = pd.read_csv('circle1.csv', header=None, names=['Value'])
df

     Value
0  0.083003
1  0.572146
2  0.465181

df ** 2

      Value
0  0.006889
1  0.327351
2  0.216393

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM