Python with Pandas dataframe
I have a csv file that contains a large number of columns and rows. I need to write a script that concatenates some elements of the first row with some elements of the 2 row. Something like # if data[1][0] starts with ch then concatenate the element right below it. I have attached a picture of just a sample of my data. The booleans have to stay on there as is. But I must drop the empty columns. I'm just having difficulty doing this through using pandas dataframe. In order for me to run the debugger on my script I must run a main.py that is under my tools folder. Any help would be appreciated.

I do not believe my dataframe is data. Here is my code so far.

Additional information: i need to join elements that say ch1a with the element right below it to read as part of the same column title. So the first row elements have to join together with the second row elements. please let me know if this still isn't clear
ANSWER:
CODE TEXT
import pandas as pd
import numpy as np
def ImportCustomScript(filename):
data=pd.read_csv(filename,sep='.',header=None)
# droping empty columns, using dropna method of pandas with
axis=1
data=data.dropna(axis=1)
# concatenating first col and second column value if first value
starts with ch
# using list comprehension to create list of concatenated
values
# looping through each keys and fetch first and second value of
col
# if first value start with ch concatenating first and second
value
# otherwise returning first value
concatenated_values=[data[key][0]+data[key][1] if (data[key][0][:2]
=='ch') else (data[key][0]) for key in data.keys()]
# replacing values of first column to concatenated_values
data.iloc[0] = concatenated_values
return data
ImportCustomScript('dataset.csv')
CODE IMAGE

INPUT IMAGE

OUTPUT IMAGE

Python with Pandas dataframe I have a csv file that contains a large number of columns...
Pandas DataFrame in Python : I have csv file which has date column with object data type which ranges from 1908 to 2018: (Original) Date (My result) Date (I Need) Date 17-Sep-08 2008-09-17 1908-09-17 7-Sep-09 2009-09-07 1909-09-07 . (more years) . (more years) . . . . 8-Nov-07 2007-11-07 2007-11-07 23-Sep-08 2008-09-23 2008-09-23 29-Dec-18 2018-12-29 2018-12-29 When I am converting it to datetime64[ns] or/and adding column as year after extracting just year values from date...
(a) Load the data file data/tips.csv into a pandas DataFrame called tips_df using the pandas read_table() function. Check the first five rows. (b) Create a new dataframe called tips by randomly sampling 6 records from the dataframe tips_df. Refer to the sample() function documentation. (c) Add a new column to tips called idx as a list ['one', 'two', 'three', 'four', 'five', 'six'] and then later assign it as the index of tips dataframe. Display the dataframe. (d) Create a new...
How to make a table from a csv file without using prettytable or pandas. I have to use format I'm trying to... I'm trying to get a column for "Type", "Total", and "Percent" from TipJoke.csv file. import csv with open('TipJoke.csv', newline='') as csv_file: filereader = csv.reader(csv_file, delimiter=' ') for row in filereader: print( '{:2} {:3} {:4}'.format('Type', 'Total', 'Percent')) print(', '.join(row))
How to make a table from a csv file without using prettytable and without pandas. I have to use format I'm... I'm trying to get a column for "Type", "Total", and "Percent" from TipJoke.csv file. import csv with open('TipJoke.csv', newline='') as csv_file: filereader = csv.reader(csv_file, delimiter=' ') for row in filereader: print( '{:2} {:3} {:4}'.format('Type', 'Total', 'Percent')) print(', '.join(row))
Python Assignment In this assignment, you will use Pandas library to perform analysis on the dataset stored in the following csv file: breast-cancer-wisconsin.csv. Please write script(s) to do the following: 1. Read the csv file and covert the dataset into a DataFrame object. 2. Persist the dataset into a SQL table and a JASON file. • Write the content of the DataFrame object into an SQLite database table. This will convert the dataset into a SQL table format. You can...
I have a dataframe with these columns: peo means people with cancer.I encode 'peo' collum to low and hight and the have values 0 for low and 1 for hight. Egg , meat_other, mutton_goat, beed, pig , poultry are numeric values of the consumption of these types of foods. I would like to answer this question on my analysis: If this type of foods have a relation with cancer.All my variables are numeric , less country that is the names...
I have a dataframe with these columns: peo means people with cancer.I encode 'peo' collum to low and hight and the have values 0 for low and 1 for hight. Egg , meat_other, mutton_goat, beed, pig , poultry are numeric values of the consumption of these types of foods. I would like to answer this question on my analysis: If this type of foods have a relation with cancer.All my variables are numeric , less country that is the names...
Lab Exercise #15 Assignment Overview This lab exercise provides practice with Pandas data analysis library. Data Files We provide three comma-separated-value file, scores.csv , college_scorecard.csv, and mpg.csv. The first file is list of a few students and their exam grades. The second file includes data from 1996 through 2016 for all undergraduate degree-granting institutions of higher education. The data about the institution will help the students to make decision about the institution for their higher education such as student completion,...
PYTHON: I have a numpy array that holds a name and a phone number such as this one. import numpy as np import pandas as pd LIST = np.array([("James", "Kirk", "512-375-5585"), ("Richard", "Branson, "1234567890"), ("James", "Bond", "34567")]) Then I stuff it into a data frame by doing this df = pd.DataFrame(List, columns=('Firstname', 'Lastname', 'Phone')) How would I go about changing 10 digit phone numbers such as 1234567890 into 123-456-7890 and discarding invalid ones such as 34567 so it reflects in...
Implement a class CSVReader that reads a CSV file, and provide methods: int numbOfRows() int numberOfFields(int row) String field(int row, int column) Please use the CSVReader and CSVReaderTester class to complete the code. I have my own CSV files and cannot copy them to here. So if possible, just use a random CSV file. CSVReader.java import java.util.ArrayList; import java.util.Scanner; import java.io.*; /** Class to read and process the contents of a standard CSV file */ public class CSVReader {...