【问题标题】:Python Select Specific Row and Column from CSV filePython Select Specific Row and Column from CSV file
【发布时间】:2022-12-01 19:40:19
【问题描述】:

I want to print specific row and column from a csv file. csv file look like,

R,IMSI,DATE FIRST EVENT,TIME FIRST EVENT,DATE LAST EVENT,TIME LAST EVENT,DC(HHMMSS),NC,VOLUME,SDR R C,634012007277489,20221122,150025,20221122,150025,711,1,0,294 C,634012031576061,20221122,150859,20221122,151738,905,3,0,1597 C,634012045006518,20221122,144022,20221122,144022,902,1,0,368 R R R,END OF REPORT T,18

Output should be look like,

C,634012007277489,20221122,150025,20221122,150025,711,1,0,294 C,634012031576061,20221122,150859,20221122,151738,905,3,0,1597 C,634012045006518,20221122,144022,20221122,144022,902,1,0,368

【问题讨论】:

  • post your current code
  • Check your file data. Last line has more columns than header.

标签: python


【解决方案1】:

Use pandas (you need to install it first by pip install pandas in the terminal).

import pandas as pd

df = pd.read_csv(fullpath.csv)
x = df[column_name].iloc[row_number]

【讨论】:

    【解决方案2】:

    Try reading it with pandas.read_csv()

    import pandas as pd
    df = pd.read_csv('filename.csv', skipfooter=1, header=1)
    df.iloc[row_number,column_number]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-28
      • 2022-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-17
      • 2014-12-12
      • 2013-06-01
      相关资源
      最近更新 更多