We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
https://www.cnblogs.com/keye/p/9673393.html
iterrows(): 将DataFrame迭代为(insex, Series)对。 itertuples(): 将DataFrame迭代为元祖。 iteritems(): 将DataFrame迭代为(列名, Series)对
现有如下DataFrame数据:
import pandas as pd
inp = [{'c1':10, 'c2':100}, {'c1':11, 'c2':110}, {'c1':12, 'c2':123}] df = pd.DataFrame(inp)
print(df)
iterrows():
for date, row in df.iterrows(): print(date)
for date, row in df.iterrows(): print(row)
for date, row in df.iterrows(): print(row['c1'], row['c2'])
iteritems():
for date, row in df.iteritems(): print(date)
for date, row in df.iteritems(): print(row)
for date, row in df.iteritems(): print(row[0], row[1], row[2])
itertuples():
for row in df.itertuples(): print(row)
for row in df.itertuples(): print(getattr(row, 'c1'), getattr(row, 'c2'))
The text was updated successfully, but these errors were encountered:
No branches or pull requests
https://www.cnblogs.com/keye/p/9673393.html
iterrows(): 将DataFrame迭代为(insex, Series)对。
itertuples(): 将DataFrame迭代为元祖。
iteritems(): 将DataFrame迭代为(列名, Series)对
现有如下DataFrame数据:
import pandas as pd
inp = [{'c1':10, 'c2':100}, {'c1':11, 'c2':110}, {'c1':12, 'c2':123}]
df = pd.DataFrame(inp)
print(df)
iterrows():
for date, row in df.iterrows():
print(date)
for date, row in df.iterrows():
print(row)
对于每一行,通过列名访问对应的元素
for date, row in df.iterrows():
print(row['c1'], row['c2'])
iteritems():
for date, row in df.iteritems():
print(date)
for date, row in df.iteritems():
print(row)
for date, row in df.iteritems():
print(row[0], row[1], row[2])
itertuples():
for row in df.itertuples():
print(row)
for row in df.itertuples():
print(getattr(row, 'c1'), getattr(row, 'c2'))
The text was updated successfully, but these errors were encountered: