My issue is much. I have a csv file, and want to select where Arrival or Departure and must be the same "date and time" have the same value. I can only read from csv file but can't go further

import pandas as pd

    df = pd.read_csv("data.csv")

    row = next(df.iterrows())[1]
    print(row['x'])

error: dataframe is not defined.

I have a cvs file with 5 columns and multiple rows, as shown below:

 Author_ID      Arrival       Departure         Date                 Time
01202             Paris          New York         10/03/2011      10:00
02122             Beijin         New York         09/03/1999      21:00
07732             Paris          Kansas              10/03/2011     10:00




from the table above you can discover that some column values match. I want to extract wherever I find intersection. e.g so as we iterate whenever we encounter a row with the same values in Arrival or Depature or Author_ID and date && Time, we should extract and display 
        Take Arrival column, we have Paris from 2 different Authors, then consider the Date we have 10/03/2011 and "Time" we have 10:00. We want to know if these authors have connections with their depatures, arrivals at particular date and time.

Basically, I think I don't know how to go about it

Recommended Answers

All 3 Replies

Hi Gribouillis,
I have included your code it is still giving error

 import pandas as pd
    import datetime
    import pandas.io.data
    from pandas_datareader import data, wb

df = pd.read_csv('testfile.csv')
grouped = df.groupby(['Date','Time')]
for name, group in grouped:
    print (name)
    print(group)

I have attached the entire code.

Hi Gribouillis,
Thank you so much. I love you bro! You are the best.

import pandas as pd  
import datetime
import pandas.io.data
from pandas_datareader import data, wb

df = pd.read_csv('testfile.csv')
grouped = df.groupby(['Date','Time'])
for name, group in grouped:
    print (name)
    print(group)

Please kindly explain, why "name" and "group" as used up. It works perfectly. Meanwhile I want to save them back to cvs format with ARRIVAL OR DEPARTURE (wherever we have match) . For instance if I select 30-10-2011 to 30-10-2014, the list of those who met at the departure and those who met at arrival can be populated by grouped by the time and date

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.