Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Programming Articles - Page 1406 of 3366
324 Views
Assume you have a dataframe, the result for removing unique prefix city names are, Id City 2 3 Kolkata 3 4 Hyderabad 6 7 Haryana 8 9 Kakinada 9 10 KochinTo solve this, we will follow the steps given below −SolutionDefine a dataframeCreate an empty list to append all the city column values first char’s, l = [] for x in df['City']: l.append(x[0])Create another empty list to filter repeated char.Set for loop and if condtion to append unique char’s. It is defined below, l1 = [] for j in l: if(l.count(j)>1): if(j not in ... Read More
4K+ Views
The result for converting celsius to Fahrenheit as, Id Celsius Fahrenheit 0 1 37.5 99.5 1 2 36.0 96.8 2 3 40.0 104.0 3 4 38.5 101.3 4 5 39.0 102.2To solve this, we will follow below approaches −Solution 1Define a dataframe with ‘Id’ and ‘Celsius’ column valuesApply df.assign function inside write lambda function to convert celsius values by multiplying (9/5)*df[celsius]+32 and assign it to Fahrenheit. It is defined below −df.assign(Fahrenheit = lambda x: (9/5)*x['Celsius']+32)ExampleLet’s check the following code to get a better understanding −import pandas as pd df = pd.DataFrame({'Id':[1, 2, 3, 4, 5], ... Read More
937 Views
The result for appending magic numbers from 1 to 100 is, magic number series: 0 1 1 10 2 19 3 28 4 37 5 46 6 55 7 64 8 73 9 82 10 91 11 100To solve this, we will follow the below approaches −Solution 1Create list comprehension to append 1 to 100 values to list ls.ls = [i for i in range(1, 101)]Apply ... Read More
680 Views
Result for printing palindrome names are −Palindrome names are: Id Name 0 1 bob 2 3 hannahTo solve this, we will follow the below approaches −Solution 1Define a dataframeCreate list comprehension inside set for loop to access all the values from df[‘Name’] column using i variable and set if condition to compare i==i[::-1] then add i value to the listl = [ i for i in df['Name'] if(i==i[::-1])]Finally, check the list values present in the df[‘Name’] column using isin()df[df['Name'].isin(l)]ExampleLet’s check the following code to get a better understanding −import pandas as pd data = ... Read More
180 Views
The augmented model can be compiled using the ‘compile’ method, which also takes ‘SparseCategoricalCrossentropy’ as parameter to calculate the loss associated with training.Read More: What is TensorFlow and how Keras work with TensorFlow to create Neural Networks?We will use the Keras Sequential API, which is helpful in building a sequential model that is used to work with a plain stack of layers, where every layer has exactly one input tensor and one output tensor.A neural network that contains at least one layer is known as a convolutional layer. We can use the Convolutional Neural Network to build learning model. We are ... Read More
260 Views
Tensorflow can be used to reduce overfitting using dropout technique where a sequential model is created that consists of a Rescaling layer, and the augmented data as its layers.Read More: What is TensorFlow and how Keras work with TensorFlow to create Neural Networks?We will use the Keras Sequential API, which is helpful in building a sequential model that is used to work with a plain stack of layers, where every layer has exactly one input tensor and one output tensor.A neural network that contains at least one layer is known as a convolutional layer. We can use the Convolutional Neural ... Read More
255 Views
The augmented data can be visualized using Tensorflow and Python with the help of ‘matplotlib’ library. The images are iterated over, and plotted using ‘imshow’ method.Read More: What is TensorFlow and how Keras work with TensorFlow to create Neural Networks?We will use the Keras Sequential API, which is helpful in building a sequential model that is used to work with a plain stack of layers, where every layer has exactly one input tensor and one output tensor.A neural network that contains at least one layer is known as a convolutional layer. We can use the Convolutional Neural Network to build ... Read More
276 Views
Assume, you have a time series and the result for localize asian time zone as, Index is: DatetimeIndex(['2020-01-05 00:30:00+05:30', '2020-01-12 00:30:00+05:30', '2020-01-19 00:30:00+05:30', '2020-01-26 00:30:00+05:30', '2020-02-02 00:30:00+05:30'], dtype='datetime64[ns, Asia/Calcutta]', freq='W-SUN')SolutionDefine a dataframeCreate time series using pd.date_range() function with start as ‘2020-01-01 00:30’, periods=5 and tz = ‘Asia/Calcutta’ then store it as time_index.time_index = pd.date_range('2020-01-01 00:30', periods = 5, freq ='W', tz = 'Asia/Calcutta')Set df.index to store localized time zone from time_indexdf.index = time_indexFinally print the localized timezoneExampleLet’s check the ... Read More
10K+ Views
Assume, you have datetime column in dataframe and the result for separating date and time as, datetime date time 0 2020-01-01 07:00:00 2020-01-06 07:00:00 1 2020-01-02 07:00:00 2020-01-06 07:00:00 2 2020-01-03 07:00:00 2020-01-06 07:00:00 3 2020-01-04 07:00:00 2020-01-06 07:00:00 4 2020-01-05 07:00:00 2020-01-06 07:00:00 5 2020-01-06 07:00:00 2020-01-06 07:00:00To solve this, we will follow the below approaches −Solution 1Define a dataframe ‘datetime’ column using pd.date_range(). It is defined below, pd.DataFrame({'datetime':pd.date_range('2020-01-01 07:00', periods=6)})Set for loop d variable to access df[‘datetime’] column one by one.Convert date and time from for loop and save it as df[‘date’] ... Read More
Write a program in Python to print numeric index array with sorted distinct values in a given series
128 Views
Assume, you have a series and the numberic index with sorted distinct values are −Sorted distict values - numeric array index [2 3 0 3 2 1 4] ['apple' 'kiwi' 'mango' 'orange' 'pomegranate']To solve this, we will follow the steps given below −SolutionApply pd.factorize() function inside list of non-unique elements and save it as index, index_value.index, unique_value = pd.factorize(['mango', 'orange', 'apple', 'orange', 'mango', 'kiwi', 'pomegranate'])Print the index and elements. Result is diplayed without sorting of distinct values and its indexApply pd.factorize() inside list elements and set sort=True then save it as sorted_index, unique_valuesorted_index, unique_value = pd.factorize(['mango', 'orange', 'apple', 'orange', 'mango', ... Read More