Python Forum
Write specific rows from pandas dataframe to csv file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Write specific rows from pandas dataframe to csv file
#1
Below is my CSV file

Territory  NoOfCustomer
D00060     10
D00061     20
D00065     70
D00067     90
I have to create a Unique Id based on Number of NoOfCustomer like If NoOfCustomer <=50
then I have to create 10 different Unique ID for Territory D00060 and 10 different Unique ID for Territory D00061.

Here I read my csv file in pandas like

csv_file = 'cust_valid.csv'
df=pd.read_csv(csv_file,delimiter="|")
Filtered having customers <= 50

low_dense = df['NoOfCustomer'] <=50
And then iterted low_dense like

for idx, item in df[low_dense].iterrows():
???

Now I will have to create 10 records means 10 unique ID using UUID for each territory having customers <=50? I am very new to python help me out!! Undecided
Reply


Messages In This Thread
Write specific rows from pandas dataframe to csv file - by pradeepkumarbe - Oct-18-2018, 07:48 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question [Solved] Formatting cells of a pandas dataframe into an OpenDocument ods spreadsheet Calab 1 522 Mar-01-2025, 04:51 AM
Last Post: Calab
  Find duplicates in a pandas dataframe list column on other rows Calab 2 1,965 Sep-18-2024, 07:38 PM
Last Post: Calab
  Find strings by index from a list of indexes in a different Pandas dataframe column Calab 3 1,561 Aug-26-2024, 04:52 PM
Last Post: Calab
  Loop over dataframe to fill in missing rows Scott 9 3,526 Jul-12-2024, 05:54 AM
Last Post: Scott
  Add NER output to pandas dataframe dg3000 0 1,118 Apr-22-2024, 08:14 PM
Last Post: dg3000
  HTML Decoder pandas dataframe column mbrown009 3 2,585 Sep-29-2023, 05:56 PM
Last Post: deanhystad
  Errors if an xlsx file has blank rows in the beginning…. tester_V 1 1,481 Aug-28-2023, 06:22 PM
Last Post: deanhystad
  Use pandas to obtain cartesian product between a dataframe of int and equations? haihal 0 1,964 Jan-06-2023, 10:53 PM
Last Post: haihal
Smile How to further boost the data read write speed using pandas tjk9501 1 1,986 Nov-14-2022, 01:46 PM
Last Post: jefsummers
  Split excel file and write output at specific row and set sheet position DSCA 0 2,702 May-12-2022, 07:29 PM
Last Post: DSCA

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020